Fix script for multiple updates

Kanna12
Tera Expert

Hello All,

 

I want to replace the new manager name in approval table. There are 400 rows that i need to replece the manager name.

How to right fix script to replece the values in table?

3 REPLIES 3

Akash4
Kilo Sage
Kilo Sage

Hi Sarsija,

Make sure to write the Fix script in right scope. Here is sample code you can start with and edit accordingly:

 

(function() {
var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('manager', 'old_manager_sys_id'); // add old sysId
gr.query();

while (gr.next()) {
gr.manager = 'new_manager_sys_id';//add your sysid
gr.update(); 
}
gs.info('Updated manager names in ' + gr.getRowCount() + ' records.');
})();

 

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Kanna12 

First of all "sysapproval_approver" table doesn't have the manager field . so the above code won't work 

The field is "Approver" and you need to change it as per your manager sys_id.

var approvalRecords = new GlideRecord('sysapproval_approver');
approvalRecords.addQuery('approver', 'prviousMangerSys_id'); // Replace with the sys_id of the old manager
approvalRecords.query();

while (approvalRecords.next()) {
approvalRecords.approver = 'your new manager sys_id'; // Replace with the sys_id of the new manager
approvalRecords.update();
}

 

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

we are maining the approval group seperatley and calling that table in workflow when ever approval needed.