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

Hi @Mark Wood,

 

You can't.

After closing the GlideModal, call a server side script (script include) with a GlideAjax call. In that script you can execute the rest of your logic.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Peter Bodelier
Giga Sage

Hi @Mark Wood,

 

Deletemultiple is not available client side, only server side.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

DYCM
Mega Sage

Hi @Mark Wood ,

Peter is correct, you are not able to run GlideModal in server side.

You will need to pop up GlideModal in UI Action then call client callable Script Include to delete records and return value from the delete function.

In UI Action, capture the returned value from Script Include function then refresh the page accordingly.

Created a table to simply show how does this work, please see below:

1. The table includes two fields: Name (String) and Age (Integer)

1.png

2. In UI Action:

2.png

Script in UI Action:

function deleteRecords() {
	var gm = new GlideModal("glide_confirm_basic", true, 600);
	gm.setTitle("Confirmation");
	gm.setPreference("title", "Are you sure you want to delete some records?");
	gm.setPreference("onPromptComplete", function () {
		var ga = new GlideAjax('x_45354_playground.DeleteRecords');
		ga.addParam('sysparm_name', 'delete');
		ga.getXMLAnswer(deleted);

		function deleted(answer) {
			if(answer=="ok"){
				g_list.refresh(1);
			}
			else{
				alert("Some went wrong!");
			}
		}
	});

	gm.setPreference("onPromptCancel", function () {
		alert("Cancelled");
	});

	gm.render();
}

 

3. In Script Include

3.png

Script in Script Include

var DeleteRecords = Class.create();
DeleteRecords.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	delete:function(){
		try{
			var gr = new GlideRecord("x_45354_playground_test");
			gr.addEncodedQuery("age>15");
			gr.query();
			gr.deleteMultiple();
			return "ok";			
		}
		catch{
			return "error";
		}		
	},
    type: 'DeleteRecords'
});