OnChange Client Script: Listen to Field from Reference

ipt_Phil
Giga Contributor

I want to call some Script Include in case the value of a field of a reference changes. However, in a Client Script I can only chose the fields of the current table and I cannot show related fields and chose fields of a reference to listen to. Strangely enough, I can listen to fields of a reference in a UI policy condition. However, I cannot get a UI policy to execute everytime the value changes. It will only change once. I think using a UI policy to achieve this would only be a work around anyway and doesn't feel like it's the right way to do this. I think an OnChange Client Script is exactly what I want for my case. Is there any good way I can solve my problem? Preferably I just want something like "Show Related Fields" for the OnChange Client Script (like I have it for a UI Policy condition).

Regards, Phil

4 REPLIES 4

Deepak Negi
Mega Sage
Mega Sage

You can use getReference() method.



Lets say if you want to use assignment group name in your client script. Then you can use "g_form.getReference('assignment_group').name".
But this you can use the fields of a reference.



If you are going to use this please follow the recommended use here.



Hope this helps!



Regards


Deepak


Unfortunately that's not what I meant. I'm talking about the field marked in yellow below. I want to execute some code when the user changes the value of the choice field "Sender.ChannelType". However there is no way to select a dotwalked field in this dropdown like it is in many other places. It only lets me select fields that are directly on the selected table itself:


Capture1.JPG


Hi Philemon,



You cannot dot-waking to the field directly via fields. However you can do the validation by using getReference at the script level.


Please let me know if you have any questions.


Hi @pradeep Sharma ,

 

Iam having a trouble same with him, but i dont get what you mean here. Please elaborate or give an example. Thank you. Iam just new in Servicenow