How to autopopulate fields from the same reference table in Service portal form

Wendy20
Tera Expert

Hi All,

 

I am working on a form in service portal and have 2 reference field from the sys_user table.   One is "user id" and the other is "email address".  I added the fields but I can't figure out how to:

1-  Populate the "user id" instead of the "user name" in the "User Id" field

2- Populate the "email address" instead of the "user name" in "Email address" field

3- Make to when user id is populated the email address is also populated and vise versa.  When users' email is selected, the "user id" will auto populate. 

 

Any advice will be greatly appreciated. Thank you in advance.

 

Kind regards,

Wendy

2 REPLIES 2

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Wendy20 ,

 

If u r working on Utah version then u can try the Auto populate functionality or check the below link please 

 

https://www.servicenow.com/community/now-platform-forum/auto-populate-values-based-on-another-field-...

 

Thanks,

Danish

 

Anwesha3
Mega Guru

Hi @Wendy20 
Hope you are doing great.
For reference Field what value would be populated , that depends on "Display Value" field on user table. 
Go tosys_dictionary , search for sys_user table and check which field has been set as display true. There is a possibility that its " user name ".

Anwesha3_0-1701617087566.png

You should not change the display field , what you can do is,
Option 1 - 
Change the field type to Single Line text. Write a script include , call that script include from client script using GlideAjax , to glideRecord on sys_user table in script include side and return both email and id to client side . on client side do se value to respective field as needed. 
Option 2 - 
Use a different field type eg. Look up select box ; give the field expected field name in 
 Lookup value field | lookup_value

Kindly consider marking the provided answer as correct if it proved helpful or mark helpful if it has contributed in someway to your query 


Thank you and best regards,
Anwesha