gsftSubmit wait for dialog to close

Mike Edmonds1
Kilo Expert

All, 

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 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.

5 REPLIES 5

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.

 

1. Create a new Client Script

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

3. I left UI Type as Desktop

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

5. I left the other options as defaults

6. In the Script block create the following function:

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) + "&gdID=" + encodeURIComponent(generateDocID) + "&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;
}

7. Check the Isolate Script checkbox

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!