How to check the variable's variable set?

bill_dev
Mega Guru

How can I check the variable's variable set in a server side script.

var item = new GlideRecord("sc_req_item");

item.addQuery('sys_id', '1f6d025b13da83008a3efc04e144b0cd'); //I had RITM sysid for testing

item.query();

if(item.next()) {

gs.print(item.number + " : "+ item.cat_item.getDisplayValue());

gs.print(item.stage.getLabel()+" : "+item.stage.getDisplayValue().charAt(0).toUpperCase()+ item.stage.getDisplayValue().slice(1).replaceAll("_"," "));

for (key in item.variables) {  

  var v = item.variables[key];

  var vName = v.getGlideObject().getQuestion().getName(); //I got the name of the fields

  var vLabel = v.getGlideObject().getQuestion().getLabel(); // I got the label of the fields

 

  var vRecord = v.getGlideObject().getRefRecord(); //but I can't get the variable set name of the fields

 

  if(arrayUtil.contains(arr, vName)) {   //ignore this condition, I have a definite list of variables that I'm checking

      gs.print('         ' + vName + ' - ' + vLabel + " = " + v.getDisplayValue() + ' - ' + vRecord.getValue('variable_set'));      

  }

}

}

Please help, thanks

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Hey try this inside for loop




var gr = new GlideRecord('sc_item_option_mtom')


gr.addQuery('request_item', item.sys_id);


gr.addQuery('sc_item_option.item_option_new.name', vName );


gr.query();




if(gr.next())


    gs.print(gr.sc_item_option.item_option_new.variable_set.name)



}


View solution in original post

2 REPLIES 2

dvp
Mega Sage
Mega Sage

Hey try this inside for loop




var gr = new GlideRecord('sc_item_option_mtom')


gr.addQuery('request_item', item.sys_id);


gr.addQuery('sc_item_option.item_option_new.name', vName );


gr.query();




if(gr.next())


    gs.print(gr.sc_item_option.item_option_new.variable_set.name)



}


Yeah I thought about this, but I'm hesitant to use it because I reckon the execution time of the script will be long with a gliderecord on every variable. This is a correct solution though so I'll mark this as correct answer. Thank you for the reply.