- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
07-21-2023 04:34 AM - edited 07-21-2023 08:26 AM
Recently I was working on a requirement where I needed to write a script to remove specific users from their respective groups and remove all of their roles (given directly to them without any group) and only assign 'snc_internal' role to them.
I did not know that I was going to run into deleting the roles of all the users in DEV instance because of one wrong query. However, I was lucky enough that it did not delete my admin role (I think I was the executor of that script that's why, or it is still a mystery to me 😅).
I ran the script at the end of my day and went to sleep nicely, got to know about this when my team tried to login to DEV instance next day and they were not having admin access. I quickly checked my script and found that it ran for hours together and deleted everyone's role except mine.
I panicked and started thinking what should be done now. My teammates were suggesting that they will perform a clone from PROD to restore everyone's role. I was blank and not understanding what to do. But later after research for sometime, I figured that I can rollback my script, and after seeing this my eyes glittered and I quickly looked into 'sys_rollback_context' table and found my fix script for rollback.
Steps to rollback your script
In order to verify that you are rollbacking the correct script, you can filter it in 'From version' field on 'sys_rollback_context' table. It will show 'Fix Script:<your_script_name>'. You can only rollback the scripts which are in 'Finished Recording' state. If the state is expired then it can't be rollbacked.
Note: Below screenshots are from my PDI and do not contain the exact script records.
Once you found your script which needs to be rollbacked. Open the record and click on 'Rollback' related link.
Post this you will get a pop up 'Execute Rollback?'. Select 'yes' in that and click 'OK'. You will see the progress of rollback and once completed, click on close. And your rollback is successful.
Note: There are some other ways to recover your scripts or perform rollback and delete recovery. You can look for below document for the same. This will not help in case of Fix scripts.
I hope this article will help others who faces the same issue. Please mark it helpful and bookmark it for future reference if you feel so.
Regards,
Mohit Kaushik
ServiceNow MVP (Dev and Community)
- 15,236 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for the information. I tried to find information in the Docs and as frequently happens, there isn't any. There was a lot about rollbacks but as you said, nothing related to Fix scripts.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Rolling Back Deleted Records from a Background Script
If a record is deleted using a Background Script, we can recover it using the following methods:
Delete Recovery Module – Helps in recovering deleted records.
Script Execution History – Tracks script execution details.
Audit Deleted Records – Logs all deleted records for recovery.
Rollback Context – Allows rollback of deleted, updated, or inserted records.
Note: The "Record for Rollback" field should be checked in the script for rollback to work. It is enabled by default.
Rolling Back Deleted Records from a Fix Script
If a record is deleted using a Fix Script, you can recover it using:
Delete Recovery Module
Audit Deleted Records
Rollback Context
Note: Similar to the Background Script, the "Record for Rollback" field must be checked to enable recovery. This is usually enabled by default.
Rolling Back Inserted,Updated Records from a Fix Script
If a record is Inserted,Updated using a Fix Script, you can rollback it using Rollback Context.
I hope this will be helpful to future seekers.
Regards,
Abhijeet Pawar.