The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Auto populate catalog item variables

askari125
Tera Contributor

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.

 

3 REPLIES 3

Sai Shravan
Mega Sage

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 

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hayo Lubbers
Kilo Sage

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

Brad Bowman
Kilo Patron
Kilo Patron

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:

https://www.servicenow.com/community/developer-articles/catalog-data-lookup-definition-on-any-table-...

 

If you find something isn't working quite right in this scenario, you can use getReference

https://docs.servicenow.com/bundle/tokyo-application-development/page/app-store/dev_portal/API_refer...  

 

or GlideAjax - which is a good tool to have in your belt in any event as it is the most robust solution.

https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet-updated/ta-p/2...