Reload Form On Click Action

youngistan
Mega Contributor

Hi,

I want to get some alert when Reload Form is clicked through Right-Click UI Action. But, not able to figure out on how to get know when reload form is clicked.

Can anyone please help me out with script?

Thanks & Regards,
Amisha

4 REPLIES 4

Dan Conroy
ServiceNow Employee
ServiceNow Employee

You could create a new UI action, but the original "reload form" button will still behave the same.

Anyway, if you wanted to test, something like this would work:

Create a new UI action:

Action Name: reload.prompt.form
Client: true
On Click: onClick()

Script:

function onClick() {//this function will be run client side
var answer = confirm("Are you sure you wish to reload?");
if (answer == false) { //only continue if the user selects OK from the confirm box
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'reload.prompt.form');
}


if (typeof window == 'undefined') {
reloadForm();
}

function reloadForm() {//this function will be run server side
action.setRedirectURL(current);
}


youngistan
Mega Contributor

Hi Daniel,

Thanks for your reply.

But, creating new UI Action will result in having 2 Reload Form UI Action. as OOB is not really available in UI Action, cannot disable it.

Any thoughts?

Regards,
Amisha Parekh


Slava Savitsky
Giga Sage

To remove the OOB "Reload" form context menu option, you could comment out the following line of code in "context_form_header" UI macro:

gcm.addHref("${gs.getMessage('Reload form')}", "reloadWindow(window);");


Slava Savitsky
Giga Sage

Normally, ServiceNow displays a warning message when you try to navigate away from a form if you made any changes and did not save them. This behavior is controlled by glide.ui.dirty_form_support system property. Does it sound similar to what you are actually trying to achieve?