how to auto populate variables of a catalog item

akshay parekar3
Tera Contributor

Hello everyone, i am so new to service catalog so i need your help to achieve one task

I have created an catalog item and have added 3 variables to it

named as User, Department and manager

now whoever logs in , i want user variable to auto populate with that user's name

Department variable to auto populate with department name of that user and

Manager variable to auto populate with manager name of that user

Thanks in advance!!

3 REPLIES 3

Debasis Pati1
Tera Contributor

Hi Akshay,

In the reference varaibale user in default value you can write javascript:gs.getUserID();

This will auto populate logged in uyser name in user variable 

2-for manager and department field you can write one on change client script and call a script include from there that will bring the data from the user table for departments and manager and then from your client script you can set these variable values.

function onChange(control, oldValue, newValue, isLoading) {
	
	if (newValue == '') {
		g_form.setValue('ref_manager', '');
		
	
		return;
	}
	
	var user = g_form.getReference('ref_requested_for', populateInfo);
	function populateInfo(user) {
		
		g_form.setValue('ref_manager', user.manager);
	
		
	}
	
}

the above is the sample code

for more 

you can use the below link

https://community.servicenow.com/community?id=community_question&sys_id=770f8fa1dbdcdbc01dcaf3231f96195c

 

Regards,

Debasis

 

Hi Akshay,

If this helped you please mark it as correct this will helpout other community members as well.

 

Thanks in Advance.

 

Regards,

Debasis Pati

Pavankumar_1
Mega Patron

Hi @akshay parekar 

Use below on default value on those different reference catalog variables.

1. javascript:gs.getUserID()     -- to populate logged in user

find_real_file.png

2. javascript:gs.getUser().getRecord().getValue('manager');    --to populate the manager of logged in user.

3. javascript:gs.getUser().getRecord().getValue('department');    --- to department of the logged in user.

 

Hope you it helps you or let me know if you have any challenge.

Please Mark ✅ Correct if applicable, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar