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.

Background script for updating multiple records in user table.

Shyna1
Tera Contributor

Hi,

I need a background script that will basically update a particular field in the user record after querying from sys_user_grmember table.

requirement: I need to check in the sys_user_grmember table by querying if group is active, group.company is abc and group is active and user.project is xyz 

when i get all the lists from here , i need to update the 'designation' field(this field is present in user record in user table) of these users listed and update to a sys id .

How to write a sanitized background script for this .

 

Thanks!1

5 REPLIES 5

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

var gr= new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('Add your encoded query here');
gr.query();
while(gr.next()){

var gr1= new GlideRecord('sys_user');
gr.1addQuery(''sys_id',gr.user');
gr1.query();

if(gr1.next())

{

gr1.designation='sys_id you want to enter';

gr1.update();

}

}

Hope this helps. Please mark the answer as correct/helpful based on impact.