Can I have a client script run only when the user manually changes the field value, not when it's changed by a script?

Sheryl Lyke2
Tera Guru

I have an onChange client script that runs on a parent record (custom table) when the renewal state field changes. It then updates any child records to the same renewal state. Sometimes the user will need to only change the renewal state on a few of the child items individually. There's a business rule that runs on the child record that goes through all of the items and if there are different states, it updates the parent to 'Mixed Renewal States'. When this business rule runs, I don't want the client script to run. I only want it to run if they manually update the renewal state field on the form. Is this possible?

Thank you!

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

"I have an onChange client script that runs on a parent record (custom table) when the renewal state field changes"

Are you sure? I can't think of any valid use case to do this.

You can change a field on a record and then not save it, which is not a valid cause to trigger a change to another record. It is not considered the best practice to do this!

I strongly consider you revisit this implementation as a business rule.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

7 REPLIES 7

SanjivMeher
Kilo Patron
Kilo Patron

Yes. I think, it is like that already.

Unless a user open a UI and change something, it wont run the client script.

So even if a business rule on child trigger changes, it shouldn't trigger client script on parent.


Please mark this response as correct or helpful if it assisted you with your question.

That's what I was hoping but the client script calls a script include which writes to the log and I can see the entries when updating the child record. I'm doing it from a related list while on the parent record so maybe that's why?

Yes. That could be the reason.

Are you sure, a client script is doing that?

Because you are not suppose to update child record using an onChange client script. You should be using a Business rule to update the child records. If you use onChange client script, it will update the child state, but what if you dont save the parent record? 

So I would suggest, you confirm, it is a client script doing that.


Please mark this response as correct or helpful if it assisted you with your question.

That's a great point.