Need BG script for changing the field values.

AnandKumar1
Tera Expert

Hi Team,

We need backgroup script for updating 1 filed value in task. Since its has the choice field based on the choice only the task will move to close complete and WF will be moved to next stage. Due to some issue we are suposed to change the variable values manually.

Variable name is "BMC Status" and current field value is (4 - Automation failed and sent for manual completion) need to change with (3 - Automation successful).

 

Thanks,

Anand Kumar.

1 ACCEPTED SOLUTION

Hi Anand,

So you want to update variable within RITM or sc_task?

Is this for all RITMS belonging to particular catalog item?

var ritmRec = new GlideRecord('sc_req_item');

ritmRec.addQuery('sys_id', sysId);

ritmRec.query();

if(ritmRec.next()){

ritmRec.variables['bmc_status'] = '3 - Automation successful'; // give proper value

ritmRec.update();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

3 REPLIES 3

John Longhitano
Kilo Guru

You're going to want to test this in dev before you run it in prod.

 

However you would do something like this

//Replace 'task' with whatever table the field lives on

var gr = new GlideRecord('task');

//Replace the query with whatever records you are looking for

gr.addQuery('bmc_status', 4);

//Gets all the records that match the query

gr.query();

//iterates through the records and does something to each use if instead of while if you just want to update one record or the first record found.

while(gr.next()){

//changes value of choice field to 3

gr.setValue('bmc_status', 3);

//updates the record

gr.update();

//will print all the ticket numbers that were updated

gs.info(gr.number);

}

 

Hope this helps

AnandKumar1
Tera Expert

Hi John,

Thanks for your quick help !

The variable "bmc_status" is not the one of variables (personalized list colomns) in the task/ sc_task table. The variable is from RITM. 

 

We need script to change the value of variables which are in the RITM.

 

 

Thanks,

Anand Kumar.

Hi Anand,

So you want to update variable within RITM or sc_task?

Is this for all RITMS belonging to particular catalog item?

var ritmRec = new GlideRecord('sc_req_item');

ritmRec.addQuery('sys_id', sysId);

ritmRec.query();

if(ritmRec.next()){

ritmRec.variables['bmc_status'] = '3 - Automation successful'; // give proper value

ritmRec.update();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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