Closing Record Producer window OnSubmit throws default Leave Site message? How to prevent this?

Dhirendra Singh
Mega Sage

Closing Record producer OnSubmit() client script using window.top.close(); throws javascript error in browser.

Using - top.window.close(); works fine but shows --

"Leave Site?

Changes you made may not be saved?

Leave Cancel"

How to prevent this message getting displayed?

1 ACCEPTED SOLUTION

Dhirendra Singh
Mega Sage

Found the nifty solution --

Followed this post - 

https://blog.jackthomas.io/2019/09/07/servicenow-how-to-close-record-producer-after-submission/

 

Essentially created a UI page in my App scope as helper for all such requirements with only window.close() in client script.

Called in in producer script as producer.portal_redirect = "ui page end point";

 

This works everywhere, be standalone record producer or RP displayed inside g_modal.showframe

View solution in original post

4 REPLIES 4

Ravi Peddineni
Kilo Sage

@Dhirendra Singh Jodha 

You can clear the values of all the fields and then execute close() function. Below is the example:

g_form.clearValue('<variable name>');
top.window.onbeforeunload = null;
top.window.onunload = null;
top.window.location = 'URL for redirection';

I donot wish to clear anything as i need the backend record with all values but donot want user to see anything after submit nor want it to redirect to anywhere.

@Dhirendra Singh Jodha 

Try this in the code:

g_form.modified=false;

Dhirendra Singh
Mega Sage

Found the nifty solution --

Followed this post - 

https://blog.jackthomas.io/2019/09/07/servicenow-how-to-close-record-producer-after-submission/

 

Essentially created a UI page in my App scope as helper for all such requirements with only window.close() in client script.

Called in in producer script as producer.portal_redirect = "ui page end point";

 

This works everywhere, be standalone record producer or RP displayed inside g_modal.showframe