Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help me in background script filling the empty variable in catalog task

Dushyant Siroh
Tera Expert

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.

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Dushyant Siroh 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sarthak Kashyap
Mega Sage

Hi @Dushyant Siroh ,

 

I tried your problem in my PDI please check below script 

 

I have some variables that are mandatory 

 

 

SarthakKashyap_0-1763536674160.png

 

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

SarthakKashyap_1-1763536730076.png

 

and it updated the values 

SarthakKashyap_2-1763536754088.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak