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

Joaquin Campos
Mega Sage

Hi Siva,

Maybe you could check for specific roles in the client script and do/don't show the message based on that.

You can check roles of the logged user with:

g_user.hasRole('name of role'); 

It will be true of the user has the role or false if the user hasn't it.

Hope it helps!

 

Joaquín

siva81
Kilo Contributor

Hi Joaquin,

 

Thanks for your response. But checking the logged-in user's role will not work as the same person will try to change the status to "Approved" and after seeing the error message user will approve from the Approvers tab.

I am looking for a way to identify when the task is approved from the Approvers tab. I can use that in the client script to stop the client script.

Thanks

Siva

Hi Siva,

onChange client script works only on form and not from the list?

Can you share screenshot where the error is shown and how you are testing?

Also the script written?

Regards
Ankur

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

Hi Ankur,

Thanks for your response. Below is the client script I am using:

find_real_file.png

This script should not be fired when somebody approves the change task from the Approvers tab. Is there a way we can check when the status value is changed to "Approved" from background? 

 

Thanks

Siva