Using GlideRollbackContext API for records created via UI

Saswat4
ServiceNow Employee

Hi,
we have some playwright tests, where we create some records using UI. However, the records created are in scoped apps, hence, our record cleaner, which uses TABLE API to delete the test data/records created during the test run, is not able to delete them (for obvious restrictions on scoped apps). The only way for us is again deleting via UI. But that takes a lot of time to iterate over all the records (login as admin, navigate to respective table list view and then delete via UI action).
What I am looking for, is there a way I can use GlideRollbackContext API to track the records created during the test runs and then rollback (delete) them in batches. Have been looking but haven't yet found any suitable way of doing it. Appreciate your suggestions and pointers.

2 REPLIES 2

Rafael P
Tera Expert

Hello @Saswat4 , I hope you're doing great!

Records created via UI in scoped apps can't be deleted via TABLE API (due to scoped app restrictions), requiring manual UI deletion which is time-consuming.
Solution: GlideRollbackContext API
Use GlideRollbackContext to track and rollback records created during test runs:

// Start tracking changes var rollbackContext = new GlideRollbackContext(); rollbackContext.start(); // Your test code that creates records via UI // (records are automatically tracked) // At the end of test, rollback all changes rollbackContext.rollback();


Key Points:
  • Automatically tracks all records created during the context
  • Works with scoped apps (bypasses TABLE API restrictions)
  • Batch deletion – much faster than iterating through UI
  • Rollback scope – only affects records created within the context
Alternative Approach:
If GlideRollbackContext doesn't fully meet your needs, consider:
  1. Create a custom cleanup script that runs as admin/system user with elevated privileges
  2. Use Business Rules to auto-delete test records based on a flag field
  3. Leverage ServiceNow's test data management features if available in your instance
Best Practice: Mark test records with a unique identifier (e.g., test_run_id) so cleanup scripts can identify and delete them in batches.
This approach is much more efficient than manual UI deletion for automated test cleanup.

Saswat4
ServiceNow Employee

Hello @Rafael P Highly appreciate your response !

I have an evaluation app in a complete separate repo and it is a typescript app. This runs against an instance which contains the scoped apps. I am using playwright tests to evaluate the apps with diff tests and in the process creating some records via UI. Now, had it been a deployable plugin/app, I could have easily used GlideRollbackContext API. Had it been java plugin, I could have used RollbackContext. But you see my limitation with the typescript app not deployed to instance ?