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

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();


      }


})();


Thank you. That worked.



Here is the script I used that might help someone else.



  var rec = new GlideRecord('pm_project_task');


  rec.query();



  while (rec.next()) {


      rec.short_description = rec.u_task_name;


      rec.setWorkflow(false);


      rec.autoSysFields(false);


      rec.update();


  }


Nice work! I'll update my script to get rid of the typos!


Ayshee Chattopa
Giga Expert

Hello Chuck,

 

Can you please tell me how to do this for a single record(for testing purpose).

Below is my script :

var gr = new GlideRecord('incident');
gr.addQuery('u_next_check_time_reason','=','executive summary');
gr.query();
while (gr.next())
{


gr.setWorkflow(false);


gr.autoSysFields(false);


gr.DeleteRecord();

 

}