- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 11:48 PM
I want to check if the variable value is selected as 'yes' or 'No'. Should I write a script on OnChange or OnLoad?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 11:56 PM
Hi Shreya,
It depends on the requirement.
If you want to determine the value before submission then have onSubmit client script. If you want to change the behavior of some other field(s) based on user's selection of this field i.e. Show particular field and make it mandatory if it is 'Yes' and vice-versa when it is 'No' then have onChange client script.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 11:54 PM
it shud b onchange. because your value will change every time you select yes or no
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var question = g_form.getValue('test');// variable name
alert(question);
if (question=='yes')
{
//your logic
}
//Type appropriate comment here, and begin script below
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 11:56 PM
Hi Shreya,
It depends on the requirement.
If you want to determine the value before submission then have onSubmit client script. If you want to change the behavior of some other field(s) based on user's selection of this field i.e. Show particular field and make it mandatory if it is 'Yes' and vice-versa when it is 'No' then have onChange client script.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 01:39 AM
Hi Sherya,
As per my understanding you are asking how workflow has to check whether variable is returning YES or NO and based upon conditions workflow will route.
Then it that case you can take IF activity in workflow and write code something like this, so that if will check the variable in workflow whether it is yes or no
answer = ifScript();
function ifScript()
{
if(current.variables.your variable name == "Yes")
{
return 'yes';
}
return 'no';
}
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 01:51 AM
Shreya,
If you are confused to choose OnChange or OnLoad client script.
Best way is "Include none" in that variable and write script according to your requirement.