How to stop Client Script to trigger when you update field from Related List

siva81
Kilo Contributor

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!!

1 ACCEPTED SOLUTION

RKumar3
Tera Guru

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

View solution in original post

16 REPLIES 16

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Is there any update on this? Is this question resolved or you need some more assistance.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

DirkRedeker
Mega Sage

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

Hi

just let me know, if this issue is clarified for you, or if you need some more help.

BR

Dirk

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