Reference Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
In catalog creation, I created one variable "requested for" type "Reference", if I login with Radha Manchi the name should be populate in that variable. How should I do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @radhamanchi ,
Use variable type as requestor for or else use reference qualifier "javascript: gs.getUserID()"
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'.
Chandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @radhamanchi,
Option 1: Set Default Value in the Variable (No Script Needed)
On the variable definition of your Catalog Item, go to the Default Value field and add:
>> javascript:gs.getUserID()
This method requires no client script and automatically pre-fills the reference variable with the current user's sys_id.
Option 2: Use a Catalog Client Script (onLoad)
If you want additional flexibility or are populating multiple fields based on user selection (like email, department), use a client script:
function onLoad() {
g_form.setValue('requested_for', g_user.userID);
}
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hey @radhamanchi , I have seen the below answers however, the most optimized and recommended answer would be creating a variable 'requested for' there is now an out of the box variable named as 'requested for' which will automatically fetch the logged in users details in catalog item as well as in service portal.
You will just have to select the Type itself as 'requested for'
i.e. Type - Requested For.
Here is a screenshot for better visualization.
Mark this solution as accepted and helpful as it will be helpful for other users and readers as well.
Best Regards.
Saurabh V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday - last edited Thursday
Hi @radhamanchi Try using variable of type 'Requested For' and set the deafult value as
javascript:gs.getUserID();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Yes correct, but if you use variable type as 'requested for' there is no need to use the javascript code you have given above, the variable will itself get the logged in user to that field without any code.
Mark this solution as accepted and helpful as it will be helpful for other users and readers as well.
Best Regards.
Saurabh V.