Background script

Manu143
Tera Contributor

Hi Community,

 How to write the fix script  to set the yes/no variable as yes for  the existing RITMS if the doallar amount value is greater  than or equal to 100000 .

 

Thanks,

Manu

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hello @Manu143 

 

As you wanted to update the variable ...Can you try like below 

 

var grRitm = new GlideRecord('sc_req_item');
grRitm.addEncodedQuery('Query where dollor amount is gt or et 10000');   //your query
grRitm.query();

while(grRitm.next()){
//use variables.<variable name>
grRitm.variables.<your_variable_name> = 'Yes';   //use backend value 
grRitm.update();
}

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Anubhav24
Mega Sage
Mega Sage

Hi @Manu143 ,

By variable updation you mean , the questions asked to user while the user is submitting a request if yes then you need to use below script:

 

function setTemplateValueByRitmID(ritmID, templateValue, optionValue) {
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get(ritmID)) {
gs.log('Matched with ' + ritmGr.number + 'Matched from ' + templateValue);
ritmGr.<variable name> = optionValue;
ritmGr.setWorkflow(false);
ritmGr.autoSysFields(false);
ritmGr.update();
}
}

var optGr = new GlideRecord('sc_item_option_mtom');
optGr.orderBy('request_item');
optGr.addEncodedQuery('what ever is the catalog item and its variable value conditions');
optGr.query();

while (optGr.next()) {
setTemplateValueByRitmID(optGr.request_item, optGr.request_item.number, optGr.sc_item_option.value);
}
gs.log('Updation ends');

 

You can customise it the way you want.

 

Please mark helpful/correct if my response helped you.