Variable set Mandatory!!

Kusuma2
Kilo Guru

Hi Team,

We have more that 60 variables in the variable set .we need to make these variables mandatory in a catalog item.

I am trying to make a variable set mandatory but Not working,Is it possible to make the entire variable set mandatory.

script

function onLoad() {

    //Type appropriate comment here, and begin script below

    g_form.setMandatory('ServerType2',true);           //variable set name: ServerType2

}

Working for dispaly

g_form.setDisplay(' ServerType2',true);

Regards,

Ajay.

8 REPLIES 8

harishdasari
Tera Guru

Hi Ajay,



Create Catalog UI policy on that variable set, with empty condition



find_real_file.png



Now below of it


find_real_file.png



Now make all the variables mandatory.



Instead of coding this will simple approach.



Thanks


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Ajay



Unfortunately you need to set each variable mandatory.


Maybe you can create some async Ajax call to recall the variable set, store all the variables into an array and than using the array make them mandatory



Cheers


R0b0


Dear Ajay,



I second with the approach that R0b0 suggested. Let us know if u need help with scripting.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ajay,



One thing you can do is query the "item_option_new" table with the variable set sys_id and get all the variable names. iterate over this and make those as mandatory.



var gr = new GlideRecord('item_option_new');


gr.addQuery('variable_set','034b5e724f832200fc11fa218110c73a'); // sys_id of the variable set


gr.query();


while(gr.next()){


g_form.setMandatory(gr.name,true);


}



If you want to optimize that then have GlideAjax and return an array of variable names from script include and then iterate that array in client script and then make it as mandatory true.



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