- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Everyone,
I have a Catalog Item with a Reference variable called Traveler Name that points to the user table. I want this field to automatically show the currently logged‑in user when the item is opened in Service Portal. I have tried setting a default value but it does not consistently work in Service Portal. Can someone please confirm if there is a supported way to set a default value so that the current user automatically appears or if using a Catalog Client Script on load is the recommended and reliable approach? Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello Azeem,
If possible then instead of going with the reference type variable you can go with requested for variable which will automatically populate currently logged in user. It references to the sys_user table itself.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @AzeemullahA ,
- Use onLoad Catalog Client Scripts or dynamic defaults like “current user,” “current date,” or values dependent on other variables.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Why not just default value?
- Default values on reference variables may work in the native UI but are not consistently honored in Service Portal.
- Client scripts run reliably in both UI and Portal, making them the best practice for dynamic defaults.
function onLoad() {
// Get the logged-in user sys_id
var currentUser = g_user.getUserID;
// Set Traveler Name variable to current user
g_form.setValue('traveler_name', currentUser);
}
- g_user.getUserID : returns the sys_id of the logged‑in user.
- g_form.setValue() : sets the Reference variable to that sys_id, so the user’s display name will appear automatically.
--------------------------------------------------------------------------------------------------------------------------------------------
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The recommended approach is to use the Default Value
Is this what you tried? I have never heard of this not consistently working in Service Portal. What are the conditions under which this is not working for you - only with certain users, browser, computer, or always when impersonating a certain user...?
You can use an onLoad Catalog Client Script as an alternate approach, but really shouldn't need to.
function onLoad() {
g_form.setValue("variable_name", g_user.getUserID()); //use your variable name
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yaa I know Brad,
But i want to perform this through attributes. I know it is possible through client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello Azeem,
If possible then instead of going with the reference type variable you can go with requested for variable which will automatically populate currently logged in user. It references to the sys_user table itself.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @AzeemullahA ,
- Use onLoad Catalog Client Scripts or dynamic defaults like “current user,” “current date,” or values dependent on other variables.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Why not just default value?
- Default values on reference variables may work in the native UI but are not consistently honored in Service Portal.
- Client scripts run reliably in both UI and Portal, making them the best practice for dynamic defaults.
function onLoad() {
// Get the logged-in user sys_id
var currentUser = g_user.getUserID;
// Set Traveler Name variable to current user
g_form.setValue('traveler_name', currentUser);
}
- g_user.getUserID : returns the sys_id of the logged‑in user.
- g_form.setValue() : sets the Reference variable to that sys_id, so the user’s display name will appear automatically.
--------------------------------------------------------------------------------------------------------------------------------------------
If my response helped, please mark it as the accepted solution so others can benefit as well.
