Possible to Pass Variables Between Client Scripts? (LONDON)

Chris Sanford1
Kilo Guru

I have the following requirement for the incident form: If the state changes to on hold, or the priority is escalated (changes to numeric value less than previous value), comments should be mandatory.

Sounds simple, but no luck in practice. My thought was to run two different client scripts, one on change of state and the other on change of priority. The problem is, in my client script on change of state I have no way to check if the priority was escalated or not. If the state changes from on hold back to something else I would want to make comments not mandatory, only if there is not a priority escalation.

Is there a way I could pass a flag from one client script to the other?

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You can achieve these requirements using business rule.

You can check if priority or state is changed, and then implement your validation in business rule.

 

Regards,

Sachin

View solution in original post

13 REPLIES 13

asifnoor
Kilo Patron

Hi Chris,

You cannot pass any data between client scripts. However, you can use a hidden field in the form and can achieve this.

On change of priority as per your requirement, you set the value of priority in the hidden field. On the change of state, you can access the hidden field value and can check in combination with state value and make the comments field mandatory using g_form.setMandatory()

Hope this helps.

Mark the answer as correct and helpful if this helps.

Hi,

Did you try the solution given above?

I ended up going with the solution of using a business rule instead of a client script for the validation. But thank you for the suggestion as that would likely work as well.

Hi Asifnoor,

I had a similar requirement and I tried using the hidden field in the client script as you have suggested and I wrote an OnLoad script to hide the field on form load since unchecking the visibility options in the variable did not store the value in the hidden field so when I tried to hide it (g_form.setVisible('hiddenfield',false)) in On Load script it worked for me.

Thanks

Prateek kumar
Mega Sage

Why not use a display Business rule and store the value in g_scratchpad variable and pass that information on to Client Script.

https://servicenowgems.com/2016/10/10/understanding-scratchpad-g_scratchpad/


Please mark my response as correct and helpful if it helped solved your question.
-Thanks