- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2017 02:41 PM
On Istanbul for 4 months.
I have created a Catalog Item with variables for entering the Department ID and Accounting Unit values. I am being asked to auto-populate these two variables based on the person submitting the request.
I am able to do so with a Run Script activity on the associated workflow that dot-walks to the desired field.
current.variables.au = current.request.requested_for.department.id;
current.variables.company = current.request.requested_for.cost_center.code;
Our goal is to have the 'au' and 'company' variables visible on the Catalog Item view (Service Portal) and auto-populate. The purpose being is for ordering items and there may come a time when an order is placed that will need to be charged to a different au/company than the person ordering.
Will a similar script work and where do I place this? Any assistance is appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2017 06:52 AM
Hi Kevin,
Reference fields contain two bits of information. A sys_id (which is the unique ID of the field you are referencing) and a display value - one of the fields from the referenced record to be human friendly. Because not too many humans know which user, client script, or ACL this is: 24b9bd5d9363220028517a75e57ffb1d
So to do that, there's a third argument that you cited "displayValue". Someone has defined a field on the company table and department table as the display value. You did a great job in retrieving the sys_id, the record to reference, but the system says "What am I supposed to show the users as a friendly display value?" so it runs back to the server to get that. You have the opportunity to get it with getReferenceAdvanced(). While I haven't used getReferenceAdvanced() enough to remember, based on your example, you could get it like this:
var reqFor = getReferenceAdvancedPortal(g_form, "opened_by", "department.sys_id;department.name;cost_center.sys_id;cost_center.name");
g_form.setValue("company", reqFor.cost_center_sys_id, reqFor.cost_center_name);
g_form.setValue("au", reqFor.department_sys_id, reqFor.department_name);
Visually, it will look the same, but improve performance by only doing a single server call.
Take a look at the Quick tip in Episode 39 of TechNow for more information on display values...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 10:27 AM
I set the Variable Name to au, expecting the au variable to auto-populate. Tested and still nothing appeared.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2017 02:55 PM
Hi Kevin,
Seems like you only need those two fields visible on Requested Item(RITM) level. I would suggest you create variables and hide them on the Catalog Item using a UI policy, that way they will be visible on RITM and you can edit those variables. You can populate them initially by adding the same logic you used to populate department id and cost center in the same run script.
Thanks,
Nitin.
Hit Like, Helpful or Correct based on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2017 08:33 AM
I almost never make br changes to the item table for a single item... instead what i would do if this is for only one item is to create an ajax call to the database to retrieve the information.. and populate acordingly....
if this is for multiple catalog items i would put the variables in a variable set with the call and you can just add that variable set to the items that need it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 07:51 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2017 06:18 AM
Hi Kevin,
Just a note - I also recommend getting the display value when using g_form.setValue() on a reference field. There's a third argument that is needed for reference fields/variables. Without it, the system only has a sys_id and makes another trip back to the server for each setValue() call to get the display value that goes with the sys_id. That makes 3 server calls instead of 1 like you would expect.