Fix script for multiple updates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 09:35 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 10:14 PM
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.');
})();
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 10:29 PM - edited 09-24-2024 10:31 PM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 07:30 AM
we are maining the approval group seperatley and calling that table in workflow when ever approval needed.