Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get value of variable from catalog item in catalog task client script?

Community Alums
Not applicable

Hi All,

How can I make one field on catalog task form read only based on value selected in catalog item variable?

I have tried below code to get value of variable but not getting result.

g_form.getValue('variables.assignment_group');

Please provide your suggestions on this.

Thank you!!

 

 
 
0 Helpful
 
1 REPLY 1

Allen Andreas
Tera Patron

Hello,

You can get the value of a field on the form by using:

g_form.getValue('field_name');

The above will get the value of both form fields and variables.

If you have a form field AND a variable named the same, then using the above will only get the form field whereas:

g_form.getValue('variables.field_name');

Will get the value of the variable that has the same name as a form field.

In your scenario, do you have both a form field AND a variable named assignment_group? And you're trying to get the value of the variable field named: assignment_group? If not...and you're trying to get the value of a form field named assignment_group, then please use the 1st example I gave.

 

From there, you can evaluate as you need and then set a field or variable to read only by using:

g_form.setReadOnly('field_name', true); //for form fields or unique variable names otherwise...
g_form.setReadOnly('variables.field_name', true); //for variables that are named the same as form fields

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!