script include delete record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:47 PM
I want to delete the records in the table whose system name is the same as the status of abolished,
Executed when the next record is created。Urgently need your help
var CommonInfo_Grr = new GlideRecord('table');
//CommonInfo_Grr.initialize();
CommonInfo_Grr.addQuery("status", "abolished");
CommonInfo_Grr.addQuery("system_name",current.getValue("system_name"));
CommonInfo_Grr.query();
while(CommonInfo_Grr.next()) {
CommonInfo_Grr.addQuery("status", "abolished");
CommonInfo_Grr.deleteMultiple();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:17 PM
Hi,
If you use deleteMultiple then please remove while loop and also if this script is in script include then pass the system_name value from where you are calling it and use that instead of current.getValue("system_name")
E.g.
deleteRecord: function(system_name) {
var CommonInfo_Grr = new GlideRecord('table');
CommonInfo_Grr.addQuery("status", "abolished");
CommonInfo_Grr.addQuery("system_name", system_name);
CommonInfo_Grr.query();
CommonInfo_Grr.deleteMultiple();
},
If you want to delete one by one then use deleteRecord() inside while loop
deleteRecords: function(system_name){
var CommonInfo_Grr = new GlideRecord('table');
CommonInfo_Grr.addQuery("status", "abolished");
CommonInfo_Grr.addQuery("system_name", system_name);
CommonInfo_Grr.query();
while(CommonInfo_Grr.next()) {
CommonInfo_Grr.deleteRecord();
}
},
Hope that helps!
Regards,
Muhammad
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:18 PM
If you still have some confusions please share some screenshot of your script include and from where you are calling this method so that we can further guide you on this.
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:24 PM
thank you very much

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:28 PM
Muhammad