Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client Script not triggered when using "Close Task" UI Action

linoyv691904179
Tera Contributor

Hi,

 

I’m facing an issue with a Catalog Task setup.

 

I created a Catalog Client Script (onLoad) that defines when a specific variable should be displayed based on certain conditions.
In addition, I created a Client Script (onChange) that should make this variable mandatory when those same conditions are met and the task is being closed (state changes to Closed Complete).

However, this logic only works when I manually change the state field, and does not trigger when clicking the "Close Task" UI Action buttonIn that case, the task is closed first, and only afterward does the variable become mandatory.

 

Has anyone encountered this behavior before or found a good approach to make the variable mandatory when closing via a UI Action?

Thanks in advance!

10 REPLIES 10

RaghavSh
Mega Patron

You will have to use g_form.getActionName() in your client script:

 

https://www.servicenow.com/community/developer-forum/getactionname/m-p/1815888

 

OR

 

you can also write your client login in UI action:

 

Refer: https://www.servicenow.com/community/itsm-articles/client-side-and-server-side-code-in-one-ui-action... 

 


Raghav
MVP 2023
LinkedIn

Why? It answers the same condition of newValue == 3 (closed complete)

@linoyv691904179 Because the client script executes before the UI action.

 

So every time we want to run some client action (mostly validations/mandatory) we write that as the client action of UI action.

 

You can find this in multiple UI actions OOB example , reopen incident.

 

IMG_6965.jpeg



Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

But this is an onChange script,  g_form.getActionName() won't work, and I don't want to add logic to the ui action since it is only a variable