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.

Bulk update using fix script

Community Alums
Not applicable

Hi, how to bulk update using fix script i just want to try update the company field using dummy data from Microsoft company to Tesla company.

Thak you in Advance

2 ACCEPTED SOLUTIONS

AnveshKumar M
Tera Sage
Tera Sage

Hi @Community Alums 

You can use updateMultiple() method on GlideRecord class. For example,

 

var gr = new GlideRecord("YOUR_TABLE_NAME");

gr.addEncodedQuery("Your_Query"); //if you want to update all records in table you can remove this line

gr.query();

 

gr.company = "Sys ID of your company record from core_company field"; //I assume your field is reference to core_company table.

gr.updateMultiple();

 

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

View solution in original post

Danish Bhairag2
Tera Sage

Hi @Community Alums ,

 

You can try something like this

 

// Define a GlideRecord query to find records with the current company name "Microsoft"

var gr = new GlideRecord('your_table_name'); // Replace 'your_table_name' with the actual table name you want to update

gr.addQuery('company', 'Microsoft');

gr.query();

 

// Loop through the records and update the company name to "Tesla"

while (gr.next()) {

    gr.company = 'Tesla';

    gr.update();

}

 

gs.info('Bulk update completed. Records with company name "Microsoft" changed to

"Tesla".');

 

Thanks,

Danish

 

View solution in original post

4 REPLIES 4

AnveshKumar M
Tera Sage
Tera Sage

Hi @Community Alums 

You can use updateMultiple() method on GlideRecord class. For example,

 

var gr = new GlideRecord("YOUR_TABLE_NAME");

gr.addEncodedQuery("Your_Query"); //if you want to update all records in table you can remove this line

gr.query();

 

gr.company = "Sys ID of your company record from core_company field"; //I assume your field is reference to core_company table.

gr.updateMultiple();

 

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

Community Alums
Not applicable

Thank you!

 

Danish Bhairag2
Tera Sage

Hi @Community Alums ,

 

You can try something like this

 

// Define a GlideRecord query to find records with the current company name "Microsoft"

var gr = new GlideRecord('your_table_name'); // Replace 'your_table_name' with the actual table name you want to update

gr.addQuery('company', 'Microsoft');

gr.query();

 

// Loop through the records and update the company name to "Tesla"

while (gr.next()) {

    gr.company = 'Tesla';

    gr.update();

}

 

gs.info('Bulk update completed. Records with company name "Microsoft" changed to

"Tesla".');

 

Thanks,

Danish

 

Community Alums
Not applicable

Thank you so much!