Records are not getting deleted via bg script/fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 07:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 07:35 AM
Hello @aagman4
You can remove while loop in your script and just get deletemultiple function called.
Otherwise, you can utilize no-code feature as per below screenshot:
If you are not aware of this check this video https://youtu.be/Zbv_niGkMTM?si=LOtFfJ1TaKQlxZt8
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 11:51 AM
Hello @aagman4
You can use either the deleteMultiple() or deleteRecord() method to delete records, depending on your requirement.
- deleteRecord(): Deletes one record at a time.
- deleteMultiple(): Deletes all records matching the query in one go.
Script using deleteMultiple():
var grUserUsage = new GlideRecord('ua_app_usage');
grUserUsage.addEncodedQuery("app_nameINGRC: Risk Management,GRC: Profiles,GRC: Policy and Compliance Management,GRC: Advanced Audit,GRC: Advanced Core,GRC: Advanced Risk,GRC: Audit Management,GRC: Performance Analytics Premium Integration,GRC: Risk Shared Common Components");
grUserUsage.query();
grUserUsage.deleteMultiple(); // Deletes all records matching the query
Script using deleteRecord():
var grUserUsage = new GlideRecord('ua_app_usage');
grUserUsage.addEncodedQuery("app_nameINGRC: Risk Management,GRC: Profiles,GRC: Policy and Compliance Management,GRC: Advanced Audit,GRC: Advanced Core,GRC: Advanced Risk,GRC: Audit Management,GRC: Performance Analytics Premium Integration,GRC: Risk Shared Common Components");
grUserUsage.query();
while (grUserUsage.next()) {
grUserUsage.deleteRecord(); // Deletes each record one at a time
}
To learn more about these methods, refer to the article: ServiceNow Glide Record deleteRecord vs deleteMultiple method
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 01:35 AM
Hello @aagman4
I hope you're doing well.
If my response helped resolve your query, kindly close the thread by marking it as helpful and accepting it as the solution.
This will make it easier for future readers in the community to find the solution.
Thank You
Juhi Poddar