How to set default value for a reference field on Catalog Item

depa
Tera Contributor

Hi,

i have a reference field service and it has always one record. My question is how can i preselect this value so as a default value on the portal? That i dont need to select it always?

 

Update: Its not a static value.

find_real_file.png

Thanks for your help.

1 ACCEPTED SOLUTION

Hi Depa,

use this then in the default value section

Note: I assume there is only 1 record in that table

Give your table name in the query of GlideRecord

javascript: getValue(); function getValue(){var gr = new GlideRecord('your_table_name'); gr.query(); if(gr.next()){return gr.sys_id;}}

find_real_file.png

Regards
Ankur

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

View solution in original post

14 REPLIES 14

@Ankur Bawiskar 

yes you are right.

Hi Depa,

use this then in the default value section

Note: I assume there is only 1 record in that table

Give your table name in the query of GlideRecord

javascript: getValue(); function getValue(){var gr = new GlideRecord('your_table_name'); gr.query(); if(gr.next()){return gr.sys_id;}}

find_real_file.png

Regards
Ankur

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

How to get logged in user detail?

Hi @TT

write this script to get loggedin user details:

 

javascript:gs.getUserID();

 

Thanks

 

 

Thanks,
Murthy

Ashley Snyder1
Giga Guru

There should be a Default tab on the variable, you should be able to place the sys_id in that tab for it to find the correct record if you're always defaulting to a static value, if that value changes you can call a script include in that field by using something like javascript: [YOUR SCRIPT INCLUDE HERE]