Records are not getting deleted via bg script/fix script

aagman4
Tera Contributor
        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.deleteMultiple();
        }
 
Please let me know if I am missing anything.
 
Thanks!
3 REPLIES 3

Viraj Hudlikar
Giga Sage

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:

VirajHudlikar_0-1737732826181.png

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.

Mastering System Data Management with ServiceNow: ServiceNow Delete and Update Jobs Explained HI ALl, Hope you are doing great. In todaystutorial we will see that is ServiceNow Dictionary Attriutes and then look into json_view and no_truncate attribute along with the demo. ServiceNow is a powerful

Juhi Poddar
Kilo Patron

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

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