how to get the variable value on catalog client script if variable type is yes/No

shreyajoshi
Kilo Expert

I want to check if the variable value is selected as 'yes' or 'No'. Should I write a script on OnChange or OnLoad?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

petterbj_rgmo
Tera Contributor

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.



  1. 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!