OnChange client script on reference field

Vijaykumar K
Tera Contributor

Hi all,

 

  • I'm looking for a request,  if "assigned to" is a some perticular user (reference to sys user table) then need to clear the value and revert back the changes on page. 

 

I'm trying the below script but it's not working as expected, it's working for every user not to specific to user sys Id. 

IMG_20231027_132801__01.jpg

1 ACCEPTED SOLUTION

ServiceNow Use6
Tera Guru

Hi @Vijaykumar K ,

You are using 'if' condition and you are using ';', so it is not entering the condition.

Regards

Suman P.

View solution in original post

11 REPLIES 11

Harsh_Deep
Giga Sage
Giga Sage

Hello @Vijaykumar K 

 

Please use this 

var assign = g_form.getValue('assigned_to'); instead of your getReference.

and in the if condition you have used ; semicolon at last please remove that as well.

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Hi @Harsh_Deep  Thnks for the reply.

 

I have tried getValue method as well , still same issue.

@Vijaykumar K Your script is onChange, what is field field name for which you are using it?
if it's assign_to, then directly use newValue == 'sys_id' (however recommendation would be not to hardcode it.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog

Suyog Aptikar
Giga Guru

@Vijaykumar K Minor observation, kindly avoid use of hardcoded sys_id in script, you should save it in system property and fetch is from scratchpad.

it would be easier in terms of maintenance for future purpose, also if sys_id changes due to any reason you don't need to go in code and change it, an update in property would reflect changes everywhere.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog