Action Assignment in playbook

JulianP32954866
Tera Guru

I have an action assignment that is configured as Server Script and it runs and calls my script include and performs some checks with no problems. It all works bar one element.

The Script Include will generate a gs.addErrorMessage which appears absolutely fine and does what I want.

However, the Action Assignment's first line is gs.flushMessages() and it does nothing. I have that same line in the Script Include.  They do not error, just do absolutely nothing.

Of course, cannot use alert in a Script Include, but wondered if there is way to make it run the Server side and then a client side script - that way I could switch to alert instead.

 

Any ideas ?

4 REPLIES 4

sachinvic
Giga Guru

@JulianP32954866 

Hi,

gs.addErrorMessage() is a server-side message API, so it may not be displayed by the Playbook Action Assignment UI in the way a form action would. gs.flushMessages() only manages the server session message queue; it does not convert the message into a client-side notification.

 

If the requirement is to show the error directly in the Playbook UI, a better approach is to have the Server Script return an outcome/message, then handle that response in a Client Script/UXF Client Action and display the message on the client side.

 

Conceptually:

Action Assignment >> Server Script >> Validation >> Return result/message >> Client Script >> display error

If you don't need the message to be rendered in the Playbook UI, another option is to use the server-side action only for the validation and handle the user feedback through the Playbook/client experience.

 

Also, check whether the action can be implemented as a UXF Client Action where the client-side notification is required. ServiceNow supports Server Script, Client Script and UXF Client Action as implementation types for actions.

the fact that gs.addErrorMesasge shows my error messages, indicates to me that gs.flushMessages() should also be able to clear whether it is in the Action Assignment or Script Include (in my case, both)

I'll have a play, but it is more the stringing together / timing that I'd need to address.

Ideally it would be clear message, process, show message or continue.

 

It needs to be a Server Script as it is working on flow data and can only happen in the action assignment server script otherwise it allows the platform to continue and the intention is to stop where it is if there is an error - aka standard validation on a standard field/variable.

Exactly. In that case, gs.addErrorMessage() is only responsible for displaying the validation message; it doesn't by itself control the Flow execution.

 

For a server-side validation, the cleaner approach is to have the Action Assignment return a validation result/status and handle that result before continuing with the next Flow step.

For example:

Validate >> Error? >> Show message / stop >> Otherwise continue

 

You should avoid relying on gs.flushMessages() for the control flow. The important part is to explicitly return a success/failure result from the server-side validation and use that result to prevent the subsequent actions from executing.

 

This keeps the validation server-side and avoids introducing a client-side dependency.

Ankur Bawiskar
Tera Patron

@JulianP32954866 

I believe action assignments which run within playbook treat this differently and hence it's not working there.

💡 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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader