Making fields mandatory in variable editor of catalog task

Abhiji322
Tera Expert

Hi ServiceNow enthusiasts,

 

I have a business requirement to make fields in the variable editor mandatory whenever catalog task is set to closed complete. We have multiple ways of doing it, but I would find g_form.setMandatory('field_name',true) as the simplest method. But the headache is that I have got handful of tasks to apply the same configuration. The flow is set to add different variables in different tasks making it difficult to use the above mentioned line of code for every field. I would appreciate if someone could suggest me a way to dynamically set the variables under the variable editor task to mandatory if there is one. I can't make it mandatory by default (while configuring the variable) because it restricts people from saving the form and as per the requirement we don't want the fields to be visible on the catalog item.

 

 

Thanks in advance

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Abhiji322 

in your onChange client script on State field of sc_task you can use this syntax to determine particular task and it's variable

1) create a custom table and store there task short description (assuming it will be unique for each sc_task) and store in string field comma separated variable names which you want to make mandatory

2) then use GlideAjax and pass the short description, query that table and get the variables

3) return those variables and use this syntax to make mandatory by iterating those

g_form.setMandatory('variables.variableName', true);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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