DeleteMultiple Not working in glidemodel

Mark Wood
Tera Contributor
Hello Experts,
I have written below the UI action script This UI action is used to delete all closed incidents (we are implementing functionality to clean up incident records).script is working fine to delete a single record but in the case of deleting multiple records the below script is not working please guide me thank you.
 
 
 
function demo()
{
var gm = new GlideModal("glide_confirm_basic", true, 600);
gm.setTitle("Confirmation");
gm.setPreference("title", "Are u sure you want to delete all closed incident");
gm.setPreference("onPromptComplete", function() {
    // Inside this function, you should specify the sys_id(s) of the incident(s) you want to delete.
    var sys_id_to_delete = '46e2fee9a9fe19810049b49dee0daf58'; 
    var gr = new GlideRecord('incident');
//   gr.addQuery('sys_id', sys_id_to_delete);
gr.addQuery('state','7');
gr.setLimit(3);
    gr.query();
//gr.deleteMultiple() //tried not working
 
 
 
     if (gr.next()) {
              gr.deleteRecord();
              alert("Incident deleted successfully.");
     } 
else {
         alert("Incident not found or could not be deleted.");
     }
});
gm.setPreference("onPromptCancel", function() {
    alert("You clicked on 'Cancel'");
});
gm.render();
}

 

7 REPLIES 7

Harish Bainsla
Kilo Patron
Kilo Patron

function demo() {
var gm = new GlideModal("glide_confirm_basic", true, 600);
gm.setTitle("Confirmation");
gm.setPreference("title", "Are you sure you want to delete all closed incidents?");
gm.setPreference("onPromptComplete", function () {

var gr = new GlideRecord('incident');
gr.addQuery('state', '7');
gr.query();

var deletedCount = 0;

while (gr.next()) {
gr.deleteRecord();
deletedCount++;
}

if (deletedCount > 0) {
alert(deletedCount + " incidents deleted successfully.");
} else {
alert("No closed incidents found or could not be deleted.");
}
});

gm.setPreference("onPromptCancel", function () {
alert("You clicked on 'Cancel'");
});

gm.render();
}

Hello @Harish Bainsla ,

Thank you for your assistance.

it's working as expected. However, after deleting a record, I want to reload the list. I've used location. reload(), which indeed reloads the list, but the deleted record still appears. Strangely, when I manually refresh the page, the deleted record no longer shows up. Could you please explain why this is happening and guide me on how to resolve this issue?

I think as @Peter Bodelier  mention its server side so you can use server side script

@Harish Bainsla how can i use glidemodel in server side script.