Best way to update all records

Adam Peterson
Kilo Sage

I am working with the Project Task Table and created a field called Task Name. We are using that instead of Short Description. Well after a year or two, we want to switch back to Short Description and not use Task Name. I need to copy over the value of Task Name to Short Description on every record. What is the best way to do this? Background script? Scheduled Job? I am not the best scriptor so a little guidance would be great!

Thanks!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Adam,



For a one-off, scripts background will do it.



Standard disclaimer: The following code is untested, requires review and potential modifications.




(function () {


      var rec = new GlideRecord('pm_project_task');


      rec.query();



      while (rec.next()) {


            rec.short_description = rec.u_task_name;


            rec.setWorkflow(false); // do not trigger business rules/workflows


            rec.autoSysFields(false); // do not update system fields


            rec.update();


      }


})();


View solution in original post

5 REPLIES 5

For a single record, add

gr.setLimit(1);

before your query() call. That will tell the GlideRecord API to only fetch a maximum of 1 record.

If you're going to delete the record, then you really don't need autoSysFields() in there.

Also, change gr.DeleteRecord() to gr.deleteRecord().