Ui Action button is not working in UI native

manju12
Tera Expert

Hi Team,

 

I have one Reject button created in UI action, this button is working in workspace but same button is not working in native View.. It is throwing undefined onclick.. Shared the screenshot below. Please help me out..

 

manju12_0-1774330212811.png

 

Thanks,

Manju

3 REPLIES 3

ayushraj7012933
Mega Guru

 

Hi @manju12 ,

The error openCommentForControl is not defined clearly indicates that the function used in your UI Action onclick is not available in Native UI, even though it works in Workspace.

Root Cause

  • The function is likely defined in Workspace (UI Builder / Client Script)

  • Native UI does not load those scripts

  • Hence, onclick fails with undefined function

  • Step-by-Step Solution

Step 1: Check UI Action Configuration

  1. Go to System Definition → UI Actions

  2. Open your Reject button

  3. Verify:

    • Client = true

    • Onclick:

       
      openCommentForControl();
      Step 2: Create Client Script for Native UI
  1. Go to System Definition → Client Scripts

  2. Click New

Configure:

  • Table: same as your UI Action table

  • Type: onLoad

Step 3: Define the Function

Add this script:

function openCommentForControl() {
var comment = prompt("Enter rejection comments:");
if (comment) {
g_form.setValue('comments', comment);
}
}
 

This makes the function available in Native UI

Step 4: Test the Button

  • Open the record in Native UI

  • Click Reject

  • It should now:

    • Prompt for comment

    • Populate the field

yashkamde
Mega Sage

Hello @manju12 ,

 

ensure right client-side function scope.

because most times it’s due to missing client-side function scope also the workspace loads modules differently than UI16.

 

Also ensure Client = true and scripted in this way :

Screenshot 2026-03-24 125302.png

 

 

If my response helped mark as helpful and accept the solution.

SohamTipnis
Mega Sage

Hi @manju12,

 

This issue is happening because the function openCustomControl() is not available in the Native UI.

In Workspace, things work a bit differently; scripts can come from UI Builder or other sources, so even if the function isn’t in the UI Action itself, it may still work. But in the Native view, it strictly looks for that function inside the UI Action (or a loaded UI Script).

So when you click the button in Native UI, it tries to run openCustomControl() and fails, giving the “not defined” error.

To fix this, just make sure:

The UI Action is marked as Client = true
The same function (openCustomControl) is properly defined in the Script section of the UI Action, or available via a global UI Script

In short, I guess the function exists for Workspace but not for Native UI; that's why it breaks there.

 

Refer to these documents; this may help you:

 

https://www.servicenow.com/docs/r/application-development/ui-builder/using-ui-builder.html

https://www.servicenow.com/docs/r/security-management/security-incident-response/enable_workspace_fo...

 

 

If you find my answer useful, please mark it as helpful and correct. ‌‌‌‌‌‌‌‌‌‌‌😊


Regards,
Soham Tipnis
ServiceNow Developer ||  Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10