Quick Script to Add data to new column for all rows.

jared_wentzel
Kilo Contributor

I am looking for the easiest and quickest way to add a value to a new column for all rows in a table. This only needs to be a onetime script and I will be populating the same value 'NRFUS' to the same column 'Member Firm' on the same table 'u_assignment_assistance' for all rows. Any thoughts?

1 ACCEPTED SOLUTION

Even easier might be to:


  1. go to the list view of the table
  2. right click on the column headers
  3. click Update All
  4. click OK to accept changing all records
  5. input 'NRFUS' to the Member Firm field (without changing anything else)
  6. click Update

View solution in original post

5 REPLIES 5

Robert Beeman
Kilo Sage

Hello Jared,



Assuming, the Member Firm field is a string, and its name is u_member_firm, this should work. You can run it in the 'Scripts - Background'. You can search for it in the Application Filter.



var gr = new GlideRecord('u_assignment_assistance');


gr.query();


while(gr.next()){


gr.u_member_firm = 'NRFUS';


gr.update();


}



I would probably put a gr.setLimit(10); in between lines 1 and 2 to test first to verify that it has the expected results before you do them all.


Even easier might be to:


  1. go to the list view of the table
  2. right click on the column headers
  3. click Update All
  4. click OK to accept changing all records
  5. input 'NRFUS' to the Member Firm field (without changing anything else)
  6. click Update

i far prefer a list edit/update all over running a background script in prod!


Mike Allen
Mega Sage

var mu = new GlideMultipleUpdate(table_name);


mu.setValue('field_name',   value);


mu.execute();