onChange client scripts not triggering if onChange field is changed programatically

NToo
Tera Contributor

I made an observation and thought it worth noting here in the community.

We use Agent Workspace in our organisation, alongside NextUI.

 

I have an onChange client script that looks for changes on field A, and sets the value of field B.

Another onChange client script looks for changes on field B and performs an action.

 

I found that in Agent workspace, the second client script does not trigger when filed B is updated by the first script.

The second script triggers fine if the trigger is manual form manipulation.

 

In nextUI, the second script is triggered by the first without issue.

 

I thought it worth noting the observation in here, to see if anyone else has experienced similar.

I worked around it by merging the required logic into the first client script.

 


Steps to replicate:

Create an onChange client script that looks for changes on a field (A) and uses g_form.setValue to set field B

Create an onChange client script that looks for changes on field B

Observe that (in Agent workspace) script 2 only triggers when field B is manually changed, not when script 1 runs

 

 

1 ACCEPTED SOLUTION

@NToo 

if the 1st script is triggered via UI then 2nd should also trigger if it's onchange

Trigger for 1st script has to be from UI and then only it will work

Seems we are not able to get what you are trying to explain.

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

View solution in original post

14 REPLIES 14

Hi @NToo ,

 

So you are saying 2nd script is not event getting called in workspace view?

Did you try putting alert to check ?

Yes, thats correct. I tried removing all parts of the script, and just put an alert.

By doing this, I was able to confirm the 2nd script doesnt run.

 

The 2nd script runs fine if I manually change the field value by interacting with the form - I did this to confirm the script itself was not the issue but rather the trigger.

Which work space are you using? i tried in SOW while simple crating two onchange client script and it worked.

Hi @NToo ,

 

It should work in both, seems you have not selected UI Type = All.

RunjayPatel_0-1738057689221.png

 

Just now i have tested its working in both places if you keep UI Type=All.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

NToo
Tera Contributor

Hi Runjay,

I appreciate the response - this was indeed the first thing I checked and can confirm both scripts are set to All.

NToo_0-1738057832282.png