how to auto populate variables of a catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 11:56 PM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 05:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 08:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 09:16 AM
Hi
Use below on default value on those different reference catalog variables.
1. javascript:gs.getUserID() -- to populate logged in user
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
ServiceNow Community MVP 2024.
Thanks,
Pavankumar