How to refresh page for LIST of records using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:28 AM - edited 09-22-2023 12:31 AM
Hello Experts,
I have created a UI button that deletes all events. After deletion, I want to refresh the page. The code is working fine and refreshing the page, but it still shows the deleted record on the page after the refresh. The deleted record should not be visible. How can I achieve this? Please guide me on this.
Thank you.
UI ACTION SCRIPT
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('em_event');
gr.addQuery('state', 'closed');
// gr.setLimit(2);
gr.query();
var deletedCount = 0;
while (gr.next()) {
gr.deleteRecord();
deletedCount++;
}
if (deletedCount > 0) {
alert(deletedCount + " event deleted successfully.");
// var w = top.gsft_main || top;
//w.location.reload();
//g_list.refresh(200);
//this.window.location.reload();
//location.reload();
} 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-22-2023 12:35 AM
So on click of OK the records will be deleted?
This UI action is on list?
Possibly it's taking time to delete the records and hence showing the deleted records
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:45 AM
Yes, @Ankur Bawiskar this ui action is on the list. any solution for this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:38 AM
Hello @Mark Wood
Please refer below link, It will help you
https://www.servicenow.com/community/developer-forum/how-to-refresh-a-ui-page-after-deleting-a-recor...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:58 AM
Hello @Vaibhav , I don't want to refresh any UI page. I want to refresh the list of records only .I hope you understand my requirements.