Reference Type

radhamanchi
Tera Contributor

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?

9 REPLIES 9

SD_Chandan
Kilo Sage

Hi @radhamanchi ,

Use variable type as requestor for or else use reference qualifier "javascript: gs.getUserID()"

SD_Chandan_0-1755837362805.png



If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. 

Thank you
Chandan

kaushal_snow
Mega Sage

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.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

svirkar420
Tera Expert

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.

svirkar420_1-1757601687207.png

 

Mark this solution as accepted and helpful as it will be helpful for other users and readers as well.

Best Regards.

Saurabh V.

SunilKumar_P
Giga Sage

Hi @radhamanchi Try using variable of type 'Requested For' and set the deafult value as

javascript:gs.getUserID();

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.