- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 05:32 AM
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.
Thanks for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 06:05 AM
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;}}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 05:45 AM
Thanks for your reply, this is not a static value. Thats why i asked iam new and dunno the code to preselect the record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2020 08:38 AM
I tried that approach: the sys_id never populates in my reference variable...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 12:04 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 05:49 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 04:12 AM
Hello
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