- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 07:06 AM
Hi All,
I have a Client Script- OnChange which should prevent the users when they try to select the Approved status on the Change task form from the Status field. The script is working fine and showing an error message as expected when they select the Approved value from the Status field. But the problem I am facing is when the task is approved by the user from the Approvers tab that time also I am seeing the same error message as the script is written on OnChange.
Is there a way to prevent the Client Script firing when the task is approved from the Approvers tab?
Any help is really appreciated!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 12:48 PM
Hi Siva,
This issue occurs when we approve an item from approver's related list and status of the item changes to "Approved" without form refresh. This is called live updating and we need to make sure that your script does not run when there is a live update on the field you have written your onChange client script on.
You need to add an if condition in your client script something like below and it should work.
if(!g_form.isLiveUpdating()){
////your code
}
Please mark my answer correct if it works.
Regards,
Rajnish Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 06:43 AM
Hi Siva,
Ideally this client script as mentioned is onChange; so it would work only when field on form is changed
Are you saying it is getting triggered when some value changes in related list?
Few questions:
1) this client script is on which table
2) which related list you are referring
What is the requirement?
For checking status value changes to Approved in background you can use before update BR
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 09:47 PM
Is there any update on this? Is this question resolved or you need some more assistance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2020 03:45 AM
Hi
You can check, that your script only runs for "interactive session", like that:
gs.isInteractive(); //returns true if the session is interactive
SO, I reccomand, to raise the error message only:
a) when the value "CHANGES TO" (and not when the "VALUE IS"), AND
b) when the Session is interactive
As your client scripts only run on the form,
the value of the approval will not be set by the user,
but by some logic in the background
There is also a much simpler way to achieve this:
If you do not want your users to change the value of that field,
why don't you just set up a UI Policy to make the field "ready Only"
You also can make the field read-only based on conditions.
This way, you do not need to check this in your client scripts.
Let me know, if that answers your question and mark my answer as correct / helpful
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2020 06:10 AM
Hi
just let me know, if this issue is clarified for you, or if you need some more help.
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2020 05:06 AM
Hi
Do you have an update on this?
If your issue was solved, please mark the correct answer as correct/helpful.
Thanks for marking.
BR
Dirk