Help me in background script filling the empty variable in catalog task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago - last edited 3 hours ago
Help me in background script filling the empty variable in catalog task user faced issue in closing the task Because this is a mandatory field. check the screenshot for your reference like company name is empty please write the script for filling this value .
please help me asap.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I could see company name variable is having data in it.
Also check why user was able to close the task without filling mandatory variable.
you can use this sample script
updateVariable();
function updateVariable() {
try {
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", "IN", "sysId1,sysId2,sysId3");
gr.query();
while (gr.next()) {
gr.variables.variableName = 'your value';
gr.setWorkflow(false);
gr.update();
}
} catch (ex) {
gs.info(ex);
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9m ago
Hi @Dushyant Siroh ,
I tried your problem in my PDI please check below script
I have some variables that are mandatory
var list = new GlideRecord("sc_req_item");
list.addEncodedQuery("variables.address_1ISEMPTY^variables.cityISEMPTY^variables.zipISEMPTY^variables.locationISEMPTY");
list.query();
while (list.next()) {
gs.print("Inside IF = " + list.getValue("number"));
list.variables.address_1 = "Test";
list.variables.city = "Test";
list.variables.zip = "Test";
list.variables.location = "Test";
list.update();
}
I run my BG script for 1 RITM
and it updated the values
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
