How to create a pop-up via client script in SOW?

EJ13
Tera Contributor

I am writing a client script in the Service Operations Workspace. The intent is that is confirms that the user want to submit if the following conditions are met:

  1. State is New
  2. Assigned To and Assignment Group are not empty
  3. Any field has been changed
  4. Assigned To has not been changed

This is what I have right now:

EJ13_0-1770127341336.png

I have another one that is identical except for Global being checked and View being empty, which works when viewing the incident form in the native UI. I had read that specifying the view would make it work in SOW, but it did not. What should I do to make this work?

 

Thank you!

1 ACCEPTED SOLUTION

AnkaRaoB
Mega Guru

Hi @EJ13 ,

 

the issue is not your logic, it’s how client scripts behave in Service Operations Workspace (SOW).

 Client Scripts (onSubmit) do NOT reliably run in SOW, even if you set View = sow.

That’s why it works in the native UI but not in SOW.

Why this happens

Service Operations Workspace uses:

Now Experience / UI Framework

Declarative Actions + UI Policies

Workspace-specific scripting

Classic UI Client Scripts were designed for the platform UI, not workspaces.

So:

onSubmit client scripts

g_form.modified

control.changed()

are not consistently triggered in SOW.

Setting:

View = sow

UI Type = All

Global = true

 does not guarantee execution in SOW

This is expected behavior, not a bug.

What will work in SOW (supported approaches)

 Option 1 (Recommended): Use a Workspace Form Action

This is the correct way to do submit confirmations in SOW.

Path

 

Now Experience → UI Builder

→ Service Operations Workspace

→ Incident Record Page

→ Form Actions

Create a custom Form Action:

Trigger: Before Submit

Add a confirmation modal

Cancel submit if user clicks “Cancel”

This works 100% in SOW.

 Option 2: Use a Workspace Client Script (Advanced)

If you must script:

Use Workspace Client Scripts (not UI Client Scripts)

Attach them via UI Builder

Use nowRecord instead of g_form

Example pattern:

if (

  nowRecord.state === 1 &&

  nowRecord.assigned_to &&

  nowRecord.assignment_group &&

  nowRecord.isDirty &&

  !nowRecord.changedFields.includes('assigned_to')

) {

  return confirm('Are you sure you want to submit?');

}

 This is more complex and less maintainable than a Form Action.

If this helps you then mark it as helpful and accept it as solution.

View solution in original post

2 REPLIES 2

AnkaRaoB
Mega Guru

Hi @EJ13 ,

 

the issue is not your logic, it’s how client scripts behave in Service Operations Workspace (SOW).

 Client Scripts (onSubmit) do NOT reliably run in SOW, even if you set View = sow.

That’s why it works in the native UI but not in SOW.

Why this happens

Service Operations Workspace uses:

Now Experience / UI Framework

Declarative Actions + UI Policies

Workspace-specific scripting

Classic UI Client Scripts were designed for the platform UI, not workspaces.

So:

onSubmit client scripts

g_form.modified

control.changed()

are not consistently triggered in SOW.

Setting:

View = sow

UI Type = All

Global = true

 does not guarantee execution in SOW

This is expected behavior, not a bug.

What will work in SOW (supported approaches)

 Option 1 (Recommended): Use a Workspace Form Action

This is the correct way to do submit confirmations in SOW.

Path

 

Now Experience → UI Builder

→ Service Operations Workspace

→ Incident Record Page

→ Form Actions

Create a custom Form Action:

Trigger: Before Submit

Add a confirmation modal

Cancel submit if user clicks “Cancel”

This works 100% in SOW.

 Option 2: Use a Workspace Client Script (Advanced)

If you must script:

Use Workspace Client Scripts (not UI Client Scripts)

Attach them via UI Builder

Use nowRecord instead of g_form

Example pattern:

if (

  nowRecord.state === 1 &&

  nowRecord.assigned_to &&

  nowRecord.assignment_group &&

  nowRecord.isDirty &&

  !nowRecord.changedFields.includes('assigned_to')

) {

  return confirm('Are you sure you want to submit?');

}

 This is more complex and less maintainable than a Form Action.

If this helps you then mark it as helpful and accept it as solution.

Ankur Bawiskar
Tera Patron

@EJ13 

g_form.getControl() won't work in SOW.

you need to check if any method exists to check if any form field changed or not

If there is nothing available then your requirement is not feasible

💡 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