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.

Catalog Client Script to determine if Variable exists on form

shembop
Tera Contributor

I have a catalog item where I only present the one variable on one form, and I want to make it mandatory on a task. The reason is the answer from the tech drives the workflow path. Using a Policy to make it mandatory doesn't work well, as you cannot accept the task without also answering the question.

I thought I had found something with the g_form.hasField option, but alas, it does not seem to allow me to use that on variables.

Any way you can think of that allow me to "say" - Is the variable on the form, AND, has it been assigned to someone? - Then, make it mandatory, otherwise make it not mandatory.

3 REPLIES 3

SanjivMeher
Mega Patron
Mega Patron

Why not create a UI policy and set it to 'Apply to Requested item' and 'Apply to Catalog task' to make it mandatory, so that you dont have to create a script to check if the field exists and then make it mandatory?


Please mark this response as correct or helpful if it assisted you with your question.

As I had noted in my question -  Using a Policy to make it mandatory doesn't work well, as you cannot accept the task without also answering the variable question. So, people are having to assign it to themselves from a list view.

Would it be possible for you to check the cat_item field and then make it mandatory?

cat_item will have the sysid of the catalog item.


Please mark this response as correct or helpful if it assisted you with your question.