What is gsftsubmit and What is null in gsftsubmit

ak4
Tera Contributor

What is null in gsftsubmit

4 REPLIES 4

Pratiksha Kalam
Kilo Sage

Hello,

gsftSubmit(null, g_form.getFormElement(), "ui action id") triggers the UI Action which is specified in the 3rd parameter, which is the action name/element id.

 

It is mostly used in UI actions that have a client side and a server side script.

At the end of the client side script, you call gsftSubmit in order to trigger the UI Action again - this time running only the server side code.

 

Please also have a look at Mark Stanger's explanation:

 

http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

If answer is helpful mark correct!

Thanks,

Pratiksha

Dhananjay Pawar
Kilo Sage

Hi,

In addition to above.

gsftSubmit is used to execute the Server-side section of the script after the client-side portion has been completed successfully.

If validation is not successful at the Client side, Server-side function will not be initiated.

Passing Action name as parameter in gsftSubmit ensures the Client side validation to move ahead.

 About 'NULL' take look on below link.

https://community.servicenow.com/community?id=community_question&sys_id=d2d58b21db1cdbc01dcaf3231f96...

Hope this gives clear understanding.

 

Mark correct/helpful based on impact.

Thanks,

Dhananjay.

SwarnadeepNandy
Mega Sage

Hi,

I am not sure, if this will exactly answer your question, but at least it will give you some idea and you can dig deeper.

Steps to unravel the gsftSubmit function definition

  1. Open any ServiceNow form and open Developer Console.
  2. Go to console tab. Type "gsftSubmit" and press enter.
  3. Right click on the partial definition and click "show function definition".
  4. Now you will have the raw definition of the gsftSubmit() function.
  5. The function signature, looks something like this.

function gsftSubmit(control,  form,  action_name){} //Attached is the code.

function gsftSubmit(control, form, action_name) {
    var f;
    if (typeof form == "undefined") {
        f = findParentByTag(control, 'form');
        if (typeof form == "undefined") {
            var sectionFormId = $("section_form_id");
            if (sectionFormId)
                f = $(sectionFormId.value);
        }
    } else
        f = form;
    if (g_submitted)
        return false;
    if (typeof action_name == "undefined" && control)
        action_name = control.hasAttribute('data-action-name') ? control.getAttribute('data-action-name') : control.id;
    if (action_name == 'sysverb_delete') {
        if (!confirm(getMessage("Delete this record") + "?")) {
            g_submitted = false;
            return false;
        }
    }
    f.sys_action.value = action_name;
    if (typeof f.onsubmit == "function" && action_name != 'sysverb_back') {
        var rc = f.onsubmit();
        if (rc === false) {
            g_submitted = g_form.submitted = false;
            return false;
        }
    }
    if (control && control.getAttribute('gsft_id')) {
        action_name = control.getAttribute('gsft_id');
        f.sys_action.value = action_name;
    }
    if (action_name == 'sysverb_back')
        g_submitted = false;
    else
        g_submitted = true;
    if (typeof g_form != 'undefined' && g_form && g_submitted) {
        g_form.enableUIPolicyFields();
    }
    CustomEvent.fire("glide:form_submitted");
    try {
        GlideAjax.disableSessionMessages();
        if (isFormDataBig(f)) {
            var appendChar = (f.action.indexOf('?') === -1) ? '?' : '&';
            f.action += appendChar + 'useMultipartAwareServlet=true';
            f.enctype = 'multipart/form-data';
        }
        f.submit();
    } catch (ex) {
        GlideAjax.enableSessionMessages();
        if (ex.message.indexOf('Unspecified') == -1)
            throw ex;
    }
    return false;
}

 

gsftSubmit is basically is the submit() function of a form element in HTML. It takes the form data and sends it to server to save the data. If you inspect the "save", "insert and stay", "update", "submit" these form elements, you will find they are all internally calling gsftsubmit() function. And first parameter "control" parameter is basically HTML tag's(<form>...</form>) object state.

<button type="submit" onclick="return gsftSubmit(this);" value="sysverb_update" id="sysverb_update_bottom" data-action-name="sysverb_update" gsft_id="42df02e20a0a0b340080e61b551f2909" name="not_important">Update</button>

 

Now for 

gsftSubmit(null, g_form.getFormElement(), "ui_action_id");

In UI action you cannot get hold of the HTML tag's object state, rather we are using the second parameter which is the form element and passing the value. And as this is client side script, calling this function will always submits the form.

 

Best Regards,

Swarnadeep Nandy

The most thorough and helpful answer I've seen on this form. Thank you!