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

Thanks for your reply, this is not a static value. Thats why i asked iam new and dunno the code to preselect the record.

I tried that approach: the sys_id never populates in my reference variable...

This is exactly what I was looking for... if a sys_id could be used... and it worked very well for me. You don't need quotes surrounding sys_id either.

Allen Andreas
Administrator
Administrator

Hello,

Based on your reply to others...I'm a bit confused.

You are saying this is not a static value, correct? Then what is the filter condition on this reference field to result in only one value showing, dynamically? Which is what sounds like is going on here.

We can't really give you much more help or a script (because you're new...) without more information as to how this field is being dynamically set anyway. Because however it's being set, you really could just use that same logic/script (if applicable) to set the default value instead of just only filtering it to one result. You could do both.

So let's start there...?

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Lucas3594
Tera Contributor

Hello @Ankur Bawiskar 

 

This is exactly what I need aswell, however I get the 'invalid function definition' error.

Do you have any idea what this could be?

 

I'm on Rome by the way.

 

Thank you so much