script include delete record

kack l
Tera Expert

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();
        }

15 REPLIES 15

MrMuhammad
Giga Sage

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

Regards,
Muhammad

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.

Regards,
Muhammad

thank you very much

 

@kack l - Please let me know if this is resolved by marking the first answer as Correct. That will help future readers!

Regards,
Muhammad