How to refresh page for LIST of records using script

Mark Wood
Tera Contributor

 

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

 

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Mark Wood 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, @Ankur Bawiskar this ui action is on the list. any solution for this?

Vaibhav
Mega Guru

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.