Highlighted
Absent Member.
Absent Member.
7313 views

Is switch/case working via java in SBM?


I have a simple case statement that does not seem to fire (though no error msgs appear):

switch (Selection) {

case 1810:

ShowSection("SWInstall"); break;

case 1811:

ShowSection("SWUnInstall"); break;

default:

ShowSection("Other_Instructions"); break;

}
Tags (2)
0 Likes
12 Replies
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Oh and I did set Selection as an Int. I even hard coded it to be = 1810 just for testing. Unbelievable something so simple should not work. I am hoping it is a simple error on my part.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


The syntax above looks right, can you toss in a couple debugging Alerts to see what branch it's taking? Also double-check the names of your sections.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


The alert showed me my problem. It seems the value from getfieldvalue is the text of the field options and not the DB ID - I assume the id is not set until the submit transition completes. So, I have hide/show/etc working for transitions! Thanks. Now working on states. My if statement is showing bizzare results. It shows both conditions true (both fields hide). Something is strange. I tried putting in a alert (Selection) but it errored out.

function PageLoad()

{

var Selection = GetFieldValue("SOFTWARE REQUESTS");

if (Selection = 1810)

{

HideField("What do you need to Uninstall?");

}

if (Selection = 1811)

{

HideField("What do you need to Install?");

}

}

AddLoadCallback(PageLoad);
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


If you are actually looking for the ID, you can use GetFieldByName("FIELDNAME") and then get its internal .value. But usually going by the text value is better than the name because internal ID's change when deployed in different environments.
On the above, you need to use "==" not "=", in JavaScript the former performs a comparison, the latter sets the second value equal to the first, and returns true as long as the variable is set successfully. The perils of switching between JS and MashupScript frequently, I also commonly write + instead of & and // instead of ' 😉
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Thanks - I will make that change. Appreciate the instructions as I am obviously a newbie in the javascript world. Still have the problem that I get Nul from the Alert when I look at Selection:

var Selection = GetFieldValue("SOFTWARE REQUESTS");

Any words of wisdom on how the crack this puppy?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Maybe try using the database name... are you missing an underscore between the two words?
If you right-click on the item's frame in the SBM window and do a "View Source", you can scroll down through the HTML source and find a section called "initFieldLookup" where SBM loads the underlying DB data into the JavaScript object which is used by the AEWebservices calls. There you can see the fields which are being loaded and the names by which they are being referred.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Looking at the source I see:

...name:'SOFTWARE REQUESTS',dbName:'SOFTWARE_REQUESTS'

I have tried both names. I thought maybe the value is Nul because the field was not on the form. So I added it to the form, and then added a Hide in the script after I get its value.Still no luck. Worse, when run the script both fields dissappear:

function PageLoad()

{

var Selection = GetFieldValue("SOFTWARE REQUESTS");

HideField("SOFTWARE REQUESTS");

if (Selection = 1810)

{

HideField("What do you need to Uninstall?");

}

if (Selection = 1811)

{

HideField("What do you need to Install?");

}

}

AddLoadCallback(PageLoad);
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Actually got it - the Alert was part of the problem as it does not seem to like by parans in the field value. Just in case anyone else is interested here is the script that works. I am going to change my form to have panels and hide those as the below script still leaves blank lines where the fields are hidden, but I think the HideSection won't do that (at least it did not in hiding them in a transition). I will also change this to be a case statement. Anyway, Sheesh!

function PageLoad()

{

var Selection = GetFieldValue("SOFTWARE REQUESTS");

HideField("SOFTWARE REQUESTS");

if (Selection == "Install (add) Software")

{

HideField("What do you need to Uninstall?");

}

if (Selection == "Uninstall (remove) Software" )

{

HideField("What do you need to Install?");

}

}

AddLoadCallback(PageLoad);
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


If you click on the Panel and go to the General Properties tab in the Property Editor in Composer, there is an option called "Show lines between rows" which is checked by default... if you uncheck that it should get rid of the lines.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Sorry I was not clear - yes that gets rid of the lines, but the space where the field was is still there. So if I hide 3 fields / rows, the rows are still there even though the field does not show. I guess i should try using panels and HideSection?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Is switch/case working via java in SBM?


Yes, HideSection is the only way to get rid of the space other than using custom JavaScript that I'm aware of.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.