DeleteRecord() Method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 02:10 AM
Hello Experts,
I have written the following script in a UI action to delete all closed-state events. While the code is working as expected, it only deletes 50 records when I click on the UI action button. I want to delete all records whose state is "closed." Thank you.
function cleanup() {
var gm = new GlideModal("glide_confirm_basic", true, 600);
gm.setTitle("Confirmation");
gm.setPreference("title", "Are you sure you want to delete all closed events?");
gm.setPreference("onPromptComplete", function() {
var gr = new GlideRecord('u_ma_frm_event');
gr.addQuery('u_ma_fld_state', 'closed');
// gr.setLimit(2);
gr.query();
//gr.setWorkflow(false);
var deletedCount = 0;
while (gr.next()) {
gr.deleteRecord();
setTimeout(function() {
location.reload(true);
}, 10000);
deletedCount++;
}
if (deletedCount > 0) {
// g_list.refresh();
alert(deletedCount + " event deleted successfully.");
//g_list.refresh();
//action.setRedirectURL(current);
// window.location.reload(true);
// g_form.submit();
// var w = top.gsft_main || top;
//w.location.reload();
//this.window.location.reload();
// location.reload();
//contentWindow.location.reload(true);
// Refresh the page
} else {
alert("No closed event found or could not be deleted.");
}
});
gm.setPreference("onPromptCancel", function() {
alert("You clicked on 'Cancel'");
});
gm.render();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 03:17 AM
@palanikumar I tried already it's not working.but I will try again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 03:18 AM
@palanikumar i tried its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 07:12 AM
Hi @Mark Wood ,
I checked with the script you have provided. Issue is the timeout you have provided is not enough hence its deleting the less record rather that your expectation. I'll suggest you to increase your timeout to 20000 for 50 records or else you can do try error how much timeout you require for the operation to complete.
Try using g_navigation.reloadWindow(); as best practice in place of location.reload(true); .
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul