Make all variables not mandatory on RITM and TASK view

Marina15
Tera Expert

Hello!
Is it possible to make all variables not mandatory for RITM and TASK view using onload client script? Without the use of DOM manipulations

UI policy is uncomfortable in this case, because I have 100 variables in cat item
I know that we can make read-only all variables with g_form.setVariablesReadOnly(true). Is there something for mandatory?
Thanks in advance!

3 REPLIES 3

Mohan raj
Mega Sage

Hi @Marina15,

 

To make all variables mandatory in catalog item try below script

 

var fields = g_form.getEditableFields();
for(var x=0;x<fields.length;x++){
g_form.setMandatory(fields[x],true); 
}

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

Mohan.

Hello! It doesn't work for me

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Marina15 ,

If you are just looking for something like  g_form.setVariablesReadOnly(true) you can use  g_form.setMandatory("work_notes", true) to make the fields mandatory.

But instead if you are making the fields mandatory through UI policy on catalog form. Then you just need to uncheck the two boxes '
' and  'Applies on Requested Items' . Thus the Ui policy wont apply on RITM and TASK view and the fields will be non mandatory.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.