- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2020 09:58 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2020 10:00 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2020 10:00 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2020 10:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2020 10:04 AM
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