UI Action

surajkorade
Tera Contributor

Why is the first parameter always null in gsftSubmit(null, g_form.getFormElement(), 'server_side_script_name')?

 

I have read some documentation, but I am not able to understand the actual logic behind this.

1 ACCEPTED SOLUTION

DiveshTyagi
Kilo Guru

Hi @surajkorade ,

 

 

gsftSubmit() is a client-side function used to submit a form to the server and trigger a UI Action or server-side script.
Its typical signature is:

gsftSubmit(action, formElement, actionName);

  • action (first parameter)→ Represents the UI Action object (button/link) that triggered the submission.
    • formElement (second parameter) → The actual form DOM element being submitted.
    • scriptName (third parameter) → The name of the server-side script/UI Action to execute.

     

     

gsftSubmit(null, g_form.getFormElement(), 'server_side_script_name');​

 

The reason is:

  • The first parameter (action) is only used internally when a UI Action button is clicked directly. ServiceNow passes the button object automatically in that case.
  • When you call gsftSubmit manually (from client scripts, custom logic, or other triggers), you don’t have a UI Action object to pass.
  • So you explicitly set it to null to tell ServiceNow: “This isn’t coming from a button click; just run the script by name.”

function closeIncident() {
   gsftSubmit(null, g_form.getFormElement(), 'close_incident');
}

Here:

  • null → No button object (not triggered by a click).
  • g_form.getFormElement() → Submits the current form.
  • 'close_incident' → The name of the server-side UI Action script to run.

 

 

 

 

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------

If this information proves useful, kindly mark it as helpful or accepted solution.

 

View solution in original post

5 REPLIES 5

Bhavya11
Kilo Patron

Hi @surajkorade ,

 

Please refer below  threads for better understanding 

1. gsftSubmit(null,form element,ui action name);

2. What is gsftSubmit()'s param?? 

 

If this information proves useful, kindly mark it as helpful or accepted solution.

 

Thanks,

BK

 

 

Aditya40
Mega Guru

Hi,

 

gsftSubmit(control, form, action_name)
Parameters
control – The UI element that triggered the submit

form – The HTML form element (usually g_form.getFormElement())

action_name – The server-side script name (UI Action / Script Action)

 

ServiceNow passed the DOM element (button, link, etc.) that triggered the submit as the first argument:

gsftSubmit(this, g_form.getFormElement(), 'my_action');

This allowed the platform to:

  • Disable the clicked button

  • Identify which UI element initiated the submit

  • Prevent double-click submissions

You can still pass a DOM element, but only in rare, legacy, or highly customized scenarios:

 
gsftSubmit(this, g_form.getFormElement(), 'my_action');

 

Pass a control (button) or a form and action name if the control does not exist.

function gsftSubmit(control, /* optional */ form, /* optional */ action_name) {

Ankur Bawiskar
Tera Patron

@surajkorade 

I don't think there is a direct explanation for this available anywhere.

some explanation here from Swarnadeep

What is gsftsubmit and What is null in gsftsubmit 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

DiveshTyagi
Kilo Guru

Hi @surajkorade ,

 

 

gsftSubmit() is a client-side function used to submit a form to the server and trigger a UI Action or server-side script.
Its typical signature is:

gsftSubmit(action, formElement, actionName);

  • action (first parameter)→ Represents the UI Action object (button/link) that triggered the submission.
    • formElement (second parameter) → The actual form DOM element being submitted.
    • scriptName (third parameter) → The name of the server-side script/UI Action to execute.

     

     

gsftSubmit(null, g_form.getFormElement(), 'server_side_script_name');​

 

The reason is:

  • The first parameter (action) is only used internally when a UI Action button is clicked directly. ServiceNow passes the button object automatically in that case.
  • When you call gsftSubmit manually (from client scripts, custom logic, or other triggers), you don’t have a UI Action object to pass.
  • So you explicitly set it to null to tell ServiceNow: “This isn’t coming from a button click; just run the script by name.”

function closeIncident() {
   gsftSubmit(null, g_form.getFormElement(), 'close_incident');
}

Here:

  • null → No button object (not triggered by a click).
  • g_form.getFormElement() → Submits the current form.
  • 'close_incident' → The name of the server-side UI Action script to run.

 

 

 

 

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------

If this information proves useful, kindly mark it as helpful or accepted solution.