Custom UI action not working on FSM workspace

AbhishekK512254
Tera Contributor

I created a custom UI action: requested raised and configured in both workspace and native UI. but the custom ui action is not working either on workspace/native UI.
issue: even after clicking OOB 'save' or 'update' action on workspace, the server side of custom UI action runs every time whenever there is any updates made to the form.

expected: custom UI action should work both on client side and server side only when it is clicked.

UI action: 'Request raised'
client : true
server(insert/update) - true
script:

function poincrease() {
    var ans = confirm("Do you want to move ahead?");
    if (ans == false)
        return false;
    else
        gsftSubmit(null, g_form.getFormElement(), "req_raise");
}
if (typeof window == 'undefined')
    runBusRuleCode();

function runBusRuleCode() {
 
    current.u_status = 'req expedite required';
    current.update();
    action.setRedirectURL(current);
}

workspace client script:
function onClick(g_form) {
    var ans = confirm("Do you want to move ahead?");
    if (ans == false) {
        return false;
    } else {
        // Trigger the UI action's server-side logic.
        g_form.submit('req_raise'); // matching the UI action name
    }
}

please help to resolve this issue as i am unable to fix this issue.
 
Thanks,
Abhishek


7 REPLIES 7

AbhishekK512254
Tera Contributor

Hi @Ankur Bawiskar , my script seems correct as well. But, still it's not working. as i mentioned earlier, whenever there is any updates made on the form without clicking on custom UI action, it changes the status to 'request expedite required' . it should change the status only when custom UI action is clicked.
please help me to resolve this issue.

Thanks,

Abhishek

@AbhishekK512254 

I already showcased that the UI action works as expected

without clicking UI action how is the status moving?

Did you check that?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

_ukasz Rybicki
Giga Guru

Summary

Your custom UI action’s server code is unconditionally executed on every record save because it lacks an action.getName() guard and the script wrapper if (typeof window == 'undefined') runs on all server requests .

Problem Analysis

Unconditional server-side execution

The wrapper

if (typeof window == 'undefined')
    runBusRuleCode();

calls your server function on all server contexts (including OOB Save), so it fires on every form update .

Misconfigured Action name & Onclick

Your UI Action’s Action name must exactly match the string passed into gsftSubmit/g_form.submit. A mismatch causes the platform to fall back to the OOB update action, triggering your server script on every save .

Workspace-specific setup

Agent Workspace requires UI Actions marked Client and enabled under Workspace Form Button/Menu (or linked via a UX Form Action). Without proper workspace settings, your custom client-server flow won’t behave as expected (servicenow.com, servicenow.com).

Solution Overview

  1. Gate server logic with action.getName() so it runs only when “Request raised” is clicked.

  2. Ensure Action name is unique (e.g. req_raise) and matches client calls.

  3. Use the Onclick field for your client function.

  4. (Optional) Split into two UI Actions: one client-only, one server-only.

  5. Configure workspace settings under the UI Action’s Workspace tab or via a UX Form Action (servicenow.com, servicenow.com).

Detailed Steps

1. Update the UI Action record

  • Action name: req_raise

  • Client: ☑️

  • Server: ☑️

  • Form button: ☑️

  • Workspace Form Button: ☑️

  • Onclick: raiseRequest()

2. Refactor the Script field

// Client-side function
function raiseRequest() {
  if (!confirm("Proceed with request?")) return false;
  gsftSubmit(null, g_form.getFormElement(), action.getName());
}

// Server-side code
if (typeof window === 'undefined') {
  if (action.getName() !== 'req_raise') return;
  current.u_status = 'req expedite required';
  current.update();
  action.setRedirectURL(current);
}

 

3. (Optional) Split into two UI Actions

  • Client-only: Active, Client ☑️, Action name req_raise, Onclick raiseRequest().

  • Server-only: Active, Server ☑️, Action name req_raise, Script holds only the gated server logic.

4. Configure for Agent Workspace

  • In the UI Action’s Workspace tab:

    • Available in Agent Workspace: ☑️

    • Workspace Form Button: ☑️

  • For Configurable Workspace, create a UX Form Action that links to this UI Action. (servicenow.com, servicenow.com)

Testing

  1. Open a record and verify the Request raised button appears in both native UI and Workspace.

  2. Click Request raised: confirm dialog shows; on OK, u_status updates and record reloads.

  3. Click the standard Save/Update: your custom logic should not run (confirm no status change in logs).


Let me know if this resolves your issue!