- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 06:50 AM
I am using the following script which works fine as an onLoad client Script. However, I was wondering if it is possible to revise it to make it work as an onChange Client script
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.setDisplay('u_test_case_count', false);
var tcCount = g_form.getIntValue('u_test_case_count');
var i = tcCount;
for(i = 1; i <= tcCount; i++){
var varName = g_form.getValue("u_"+i+"_pass_fail");
if (varName == 'Fail'){
g_form.setDisplay('u_add_new_act_result',false) ;
}
}
}
Little bit about what the code is.
I have about 15 Choice fields (u_X_pass_fail, where X= 1-15) that display on a form one after another. This is achieved by clicking a button called Add New(u_add_new_act_result) which also adds a counter to another field called TC Count(u_test_case_count) . Once the choice field appears and if the selection of 'Fail' is selected, I want that Add New button to hide/disappear. I can achieve this using UI policy very easily, but client script would work easily.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 06:53 AM
Hi Shiraz,
Short answer: You need an onChange client script for each field. There is no universal "onChange for all" concept when dealing with onChange client scripts. You specify which field to watch and when it changes, the script reacts to that changed field/value.
Docs: Client Scripts
Docs: GlideForm
Client Script Best Practices - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 06:53 AM
Hi Shiraz,
Short answer: You need an onChange client script for each field. There is no universal "onChange for all" concept when dealing with onChange client scripts. You specify which field to watch and when it changes, the script reacts to that changed field/value.
Docs: Client Scripts
Docs: GlideForm
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 06:56 AM
this is exactly how i have handled such scenarios.
You basically create onchange scripts on each of these fields, and on each script you check the valye on other ones and based on that just call a function, which is in your onload script. this way you will save duplication the whole logic in each script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 02:47 PM - edited 12-14-2022 02:48 PM
what if the 'field' you were watching was a MRVS variable set? would that change the result any? this is inside a catalog task- don't care which variable inside the MRVS changes, just that the MRVS is sending any update to the multi-row question answer table. Also- we're on SanDiego now if that matters.... Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 07:14 AM
I think I am going to stick to the onLoad on this one.
Thanks for your input however.