- 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-07-2017 02:08 AM
Hi,
I think there are many people in this forum that will be able to help you, but it might be helpful with some more information.
- Are you trying to access these variables in for example on the Service Portal while standing in a record producer or catalog item?
a) If this is the case you can create an onChange catalog client script that will run when you change the variable. It can look something like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//this is where you actually get the value
var yes_no = g_form.getValue('your_variable');
if (yes_no == 'yes') {
//do something
}
2. If you are trying to access this value in a workflow you can use the current.variables.your_var_name to access the variable value, or you can do it directly in a record producer with using producer. your_var_name.
Hope this helps!