- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 06:59 AM
I've read many posts about this and followed SN Guru posting about this as well. I've tried several versions of the script below and it still won't work:
This is an onChange client script - supposed to hide a section unless Category = XVALUE. Here's my script (info messages are just so I can see what the script is doing). What have I done wrong? The section will not be hidden - shows no matter what. I've also tried as onLoad script - still no dice. Any help greatly appreciated! The info messages, btw, behave as expected. The section will not hide though.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === 'XVALUE') {
return;
}
//Type appropriate comment here, and begin script below
var sections = g_form.getSections();
var val = g_form.getValue('category');
g_form.addInfoMessage(val);
if (val == 'Firewall'){
g_form.addInfoMessage('Show ' + val);
g_form.setSectionDisplay('firewall_info', true);
}
else{
g_form.addInfoMessage('Do not show ' + val);
g_form.setSectionDisplay('firewall_info', false);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 09:40 AM
Hi Dale,
Simple suggestion is to create a UI policy and add the condition if the change type is so and so and in the UI policy add the variables and make it mandatory true and check reverse if false is checked. So obviously these fields become mandatory false and this client script will also execute.
Or in the UI policy script itself you can write a script execute if true to make the fields mandatory and section visible and in the execute if false, make them mandatory false and make the section visibility as false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 12:27 PM
Good stuff - be sure to hit the "helpful" link, then!
Another point: see this code?
g_form.getValue('category');
That gets the value of the category field, but if it's a choice field (i.e.: a drop-down) then it will return the value of the choice reference, rather than the choice contents (what's displayed).
To see what I mean, look for a drop-down field, right-click the field name (not the field itself) and from the drop-down, pick Show Choice List:
From there, you can see the value versus the (displayed) label:
The label will be a descriptive human-readable presentation of the (internal) value, but it's the value you'll be comparing against, rather than the label.
That may account for your condition following the wrong logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 12:07 PM
One more question - I'm looking at the UI policy and seeing the same problem as with Client Scripts. I need these scripts to execute on both onLoad and onChange, if that makes any sense. What is being asked for is a section that only shows when the category is xvalue. BUT onLoad is too limiting because the user would have to change the category, then save and re-load form to populate the fields. Also, if onChange, the section only appears when the field changes to a new value. So, when the form is loaded later, it's not visible. Is there a way to do both with this UI Policy approach - or client script for that matter? In other words, when the Category field is "x" (whether it just changed to that, or the form is opened with that value) make the section with its mandatory fields show - otherwise, don't show. Sounds simple, I know.
Thanks for all the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 01:46 PM
Hey Dale,
Below is an example of how I would implement your use case:
You can do the following to match your use case exactly:
- Change the table to point your specific table
- Change 'Test Field' to 'Category'
- Create a new UI Policy Action for every field that you want to be mandatory and visible
Other notes:
- The 'Reverse if false' field ensures that the Firewall Fields stay hidden when the Condition is not met
- The UI Policy check will get triggered once you click outside the input field being watched. In my example, the Firewall fields will appear once you type 'XVALUE' in the Test Field and click on a different field.
- No need to hide sections and etc
Let me know if you have any more questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 03:28 PM
Hey Dale,
i'm glad that you found my comment helpful. Please let me know if it resolved your issue and that everything is working properly now. Otherwise let me know what else you're missing so I can help you out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 07:26 PM
All of these replies were very helpful - many many thanks!
I found the UI Policy was indeed the way to go. I set up the condition and then displayed and hid the section using the execute if true (g_form.setSectionDisplay('firewall_info', true);) and execute if false (g_form.setSectionDisplay('firewall_info', false);) scripts, as Vinoth Murugan and Dave Smith suggested. I made the fields I needed mandatory by using new UI actions for each as suggested by John Oliver Mendoza. It worked really quite well - was surprised how easy it was compared to the client scripts, neither of which (onLoad or onChange) worked the way I wanted.
Thanks again for taking the time to answer my questions. Not sure whose answer to mark as the correct answer because all was very helpful.