Background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 11:40 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 12:31 AM
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();
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 12:36 AM
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.