Update records with background script

Lean S
Mega Expert

Hi Team,

I want to update a field and replicate for all records through background script. I have a field 'Name'" and update this field with combination of 2 fields 

Name = Field 1 value + XYZ + Field 2 value

Kindly Suggest me how to code it.

 

Thanks,

Lean S

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Use below sample script to update records for this field.

You will have to update table name, query, filed names etc as per your requirements.

var gr = new GlideRecord('table_name');
gr.addEncodedQuery();// add query to udpate existing records from your table
gr.query();
while(gr.next()){

gr.field_3 = gr.field_1 + " XYZ " + gr.field_2;
gr.update();


}

 

Regards,

Sachin

View solution in original post

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

Use below sample script to update records for this field.

You will have to update table name, query, filed names etc as per your requirements.

var gr = new GlideRecord('table_name');
gr.addEncodedQuery();// add query to udpate existing records from your table
gr.query();
while(gr.next()){

gr.field_3 = gr.field_1 + " XYZ " + gr.field_2;
gr.update();


}

 

Regards,

Sachin

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

The general structure of your background script should be as below, read comments

 

 var gr = new GlideRecord('<your table name>');
gr.addEncodedQuery('<pass encided query of record you have to update>');
gr.setWorkflow(false); //if you dont want any BR to run for this transaction, would help in better performance also
gr.autoSysFields(false); //if you dont want system fields to be update, ie. sys_updated_on, sys_updated_by etc
gr.name=gr.<field 1>+ 'XYZ' + <gr.Field 2>;
gr.updateMultiple();
 

-Anurag

-Anurag

Community Alums
Not applicable

HiLean,

I can suggest you to a plugin that I use every day. Its a plugin named SN Utils (Chrome + Mozilla). There you have (when you open a list and go to the tool on tab GlideRecord) the entire list with the query you need (whatever you filtered in your list view). Then its just step away to do it via backgroung script 🙂

Let me know if help needed there 🙂

 

https://chrome.google.com/webstore/detail/sn-utils-onprem/lfabkiipmidkmhplochgpbaeekjjfbch

Cheers,

Joro