Auto populate catalog item variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 09:31 AM
I have a requirement to auto populate catalog item variables.
Auto populate "Edit First Name", "Edit Last Name", "Edit BALLUFF department" and "Edit BALLUFF cost center" on the basis of "Select Identity" variable.
All these are available in "sys_user" table.
Question: Select Identity
Name: select_identity
Question: Edit First Name
Name: edit_first_name
Question: Edit Last Name
Name: edit_last_name
Question: Edit BALLUFF department
Name: edit_balluff_department
Question: Edit BALLUFF cost center
Name: edit_balluff_cost_center
I have attached screenshot for your reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 03:50 AM
Hi @askari125 ,
You can auto-populate the catalog item variables using an onchange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var userGR = new GlideRecord('sys_user');
userGR.get(newValue);
g_form.setValue('edit_first_name', userGR.first_name);
g_form.setValue('edit_last_name', userGR.last_name);
g_form.setValue('edit_balluff_department', userGR.department);
g_form.setValue('edit_balluff_cost_center', userGR.cost_center);
}
Attach this script to the select_identity variable in the catalog item
Regards,
Shravan.
Please mark as help if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 04:03 AM
Hi @askari125 ,
You can achieve this without coding. Have a look at the Catalog Data Lookup : https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/service-catalog-management...
Based on the sys_id of the user (the matcher), you can populate the other variables (the setters).
Also interesting read : https://www.servicenow.com/community/developer-articles/catalog-data-lookup-definition-on-any-table-...
Note : it needs to be in the scope of the lookup table (in your case global).
Regards,
Hayo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 04:08 AM
Executing a GlideRecord in a Client Script is limited functionality, not best practice, and unsupported. In this case it sounds like the no-code approach will work for you:
If you find something isn't working quite right in this scenario, you can use getReference
or GlideAjax - which is a good tool to have in your belt in any event as it is the most robust solution.