<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question gsftSubmit wait for dialog to close in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034504#M691430</link>
    <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dialog window that renders successfully. I need to, wait till the user enters some data and submits the dialog window, then update the form. When I try the&amp;nbsp;gsftSubmit(), the dialog render, the script keeps running, and the record is not updated after the dialog box is submitted. I have also entertained using an onSubmit() client script. Again the dialog is rendered but promptly closes with out allowing any data to be entered when the script gets to the g_form.submit() function. Any help is greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 23:36:27 GMT</pubDate>
    <dc:creator>Mike Edmonds1</dc:creator>
    <dc:date>2018-03-27T23:36:27Z</dc:date>
    <item>
      <title>gsftSubmit wait for dialog to close</title>
      <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034504#M691430</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dialog window that renders successfully. I need to, wait till the user enters some data and submits the dialog window, then update the form. When I try the&amp;nbsp;gsftSubmit(), the dialog render, the script keeps running, and the record is not updated after the dialog box is submitted. I have also entertained using an onSubmit() client script. Again the dialog is rendered but promptly closes with out allowing any data to be entered when the script gets to the g_form.submit() function. Any help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 23:36:27 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034504#M691430</guid>
      <dc:creator>Mike Edmonds1</dc:creator>
      <dc:date>2018-03-27T23:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: gsftSubmit wait for dialog to close</title>
      <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034505#M691431</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You can wait for the dialog window to close before it execute the&amp;nbsp;gsftSubmit().&lt;/P&gt;
&lt;P&gt;The better way to achieve this is to write your logic in the UI Page which is used to open the dialog window based on the user action.&lt;/P&gt;
&lt;P&gt;You can write the client script or server side script in the "processing script" of UI page.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can look at the example for the same here: &lt;A href="https://docs.servicenow.com/bundle/kingston-application-development/page/script/server-scripting/reference/r_UIPages.html" rel="nofollow"&gt;UI Page&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 23:47:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034505#M691431</guid>
      <dc:creator>Rahul Jain11</dc:creator>
      <dc:date>2018-03-27T23:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: gsftSubmit wait for dialog to close</title>
      <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034506#M691432</link>
      <description>&lt;P&gt;Rahul,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The end goal would be something like this.&lt;/P&gt;
&lt;OL&gt;&lt;LI&gt;Interact with form / enter or change information on the form&lt;/LI&gt;&lt;LI&gt;Click UI action such as Save and Close&lt;/LI&gt;&lt;LI&gt;Render dialog&lt;/LI&gt;&lt;LI&gt;Input data to daialog window&lt;/LI&gt;&lt;LI&gt;When the dialog is closed the form is submitted from the client and commits the changes to the server&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;I need the record to update on the client to grab any new data and comit to the server. The dialog is used to capture information for a custom time tracking application, I am gathering information form the current record to populate fields on it. It seems the Processing Script can populate data back to the record on the server and update it there, which is why I was hoping to use gsftSubmit. Can you think of anything else that may work?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2018 13:03:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/2034506#M691432</guid>
      <dc:creator>Mike Edmonds1</dc:creator>
      <dc:date>2018-03-28T13:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: gsftSubmit wait for dialog to close</title>
      <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/3158710#M1174344</link>
      <description>&lt;P&gt;I realize this is an older post, but in case someone comes across this and is trying to find a way to use a GlideModal in an onSubmit client script and you're running into issues where it's either looping or submitting the record before the user has a chance to confirm/validate etc on the modal window, try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	if(g_scratchpad._action_confirmed) {
		return true;
	}
	
	var dialog = new GlideModal('glide_modal_confirm', false, 300);
	dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
	dialog.setPreference('body', new GwtMessage().format("Are you sure to save?"));
	dialog.setPreference('focusTrap', true);
	dialog.setPreference('onPromptComplete', doComplete);
	dialog.setPreference('onPromptCancel', doCancel);
	
	dialog.render();
	
	return false;
	
	function doComplete() {
		g_scratchpad._action_confirmed =  true;
		gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
	}
	
	function doCancel() {
	}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Full credit to icerge on GitHub who came up with this one. I spun around with different ways to try to use gsftSubmit to get this to work.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://gist.github.com/icerge/4c29728c4a8cf0c04ef8bc8cf14519c1" target="_blank"&gt;Using modal windows in SN: GlideModal, confirm onSubmit · GitHub&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2025 16:03:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/3158710#M1174344</guid>
      <dc:creator>Tristan Elmore</dc:creator>
      <dc:date>2025-01-24T16:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: gsftSubmit wait for dialog to close</title>
      <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/3555151#M1257251</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/387005"&gt;@Tristan Elmore&lt;/a&gt;, I'm following you on the script code, but where to put it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried in the UI Action of the triggering button and not honored.&lt;BR /&gt;&lt;BR /&gt;For my use case, I have a UI Action Form button on the Incident table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;User clicks button and the modal pops the default form view for a custom table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the user clicks submit for the custom table, is when I want to trap the event and do what I need - in my case window.open and pass a custom built url to another system - yes I can go API call and all that jazz, but my preference is to go old skool with just a simple UI/UX open in a blank tab and allow the user to get an idea of what is going on in the other system. But I digress.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where's the special sauce? Or am I as usual overthinking something?&lt;BR /&gt;&lt;BR /&gt;I'm a bit new to ServiceNow, but 30 yrs in programming so, I have not figured out the page lifecycle yet of ServiceNow's architecture.&lt;BR /&gt;&lt;BR /&gt;Here's my code if so desired.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function showGenerateDocForm() {
    if (g_scratchpad._action_confirmed) {
        return true;
    }

    console.log("button clicked to generate an agreement");
    //alert("Button Clicked to Generate an Agreement 🤯 \n" + g_form.getUniqueValue());

    var modal = new GlideModalForm('Document Generation Request', 'u_generate_document');
    modal.setSysID('-1');
    //modal.setPreference('sysparm_view', 'default');
    modal.setPreference('sysparm_query', 'u_incident=' + g_form.getUniqueValue());
    //modal.render();
    //return false;

    // swing and a miss
    //var submitButton = document.querySelector("#sysverb_insert_bottom");
    //submitButton.addEventListener("click", function() {
    //    window.open("https://google.com", "_blank");
    //});

    //var dialog = new GlideModal('glide_modal_confirm', false, 300);
    //dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
    //dialog.setPreference('body', new GwtMessage().format("Are you sure to save?"));
    modal.setPreference('focusTrap', true);
    modal.setPreference('onPromptComplete', doComplete);
    modal.setPreference('onPromptCancel', doCancel);
    modal.render();
    return false;
}

function doComplete() {
    alert("nailed it");
    g_scratchpad._action_confirmed = true;
    gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
}

function doCancel() {}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2026 12:14:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/3555151#M1257251</guid>
      <dc:creator>dc3itlearn</dc:creator>
      <dc:date>2026-06-07T12:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: gsftSubmit wait for dialog to close</title>
      <link>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/3556472#M1257486</link>
      <description>&lt;P&gt;As I'm still trying to make my way around all the carved up access points in the ServiceNow Navigation Pane/Menu, Client Scripts offered the easiest solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Create a new Client Script&lt;/P&gt;&lt;P&gt;2. Select the table - for me it is the custom table u_generate_document - this is where the default form is pulling into the glide modal and the default submit button appears&lt;/P&gt;&lt;P&gt;3. I left UI Type as Desktop&lt;/P&gt;&lt;P&gt;4. The type dropdown value is set to onSubmit - this is the key because it taps into the submit event listener that is generated by the server side code on modal page render&lt;/P&gt;&lt;P&gt;5. I left the other options as defaults&lt;/P&gt;&lt;P&gt;6. In the Script block create the following function:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onSubmit() {
    // Only run when the user is creating a new record
    if (!g_form.isNewRecord())
        return true;

    // Capture values BEFORE the form submits
    var docType = g_form.getValue('u_document_type');
    var generateDocID = g_form.getValue('u_number');
    var incidentID = g_form.getValue('u_incident');
    var url = "https://your.unique.url?incidentID=" + encodeURIComponent(incidentID) + "&amp;amp;gdID=" + encodeURIComponent(generateDocID) + "&amp;amp;docType=" + encodeURIComponent(docType);

    // Redirect the user - please note, you will want to use the top property of the window object to pop out of the modal window and get back to the core browser tab in order to open a new tab
    top.window.open(url, "_blank");
    return true;
}&lt;/LI-CODE&gt;&lt;P&gt;7. Check the Isolate Script checkbox&lt;/P&gt;&lt;P&gt;This works for me in ServiceNow Australia version, personal developer instance, latest release as of the date of this post - hope this helps someone - thx!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2026 14:47:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/gsftsubmit-wait-for-dialog-to-close/m-p/3556472#M1257486</guid>
      <dc:creator>dc3itlearn</dc:creator>
      <dc:date>2026-06-09T14:47:17Z</dc:date>
    </item>
  </channel>
</rss>

