- 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-05-2017 01:55 PM
I read that over and looks promising. I have downloaded and committed the Update Set. When I went to create the onChange Client Script, I put together as seen in image below. Still not working.
I didn't really expect it to because what I struggle understanding is how can this be directed for use with my Software Request Catalog Item? Would I create a Catalog Client Script?
What am I missing?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 07:28 AM
Yes, Kevin. This needs to go in a catalog client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 07:55 AM
Chuck...first off...THANKS for helping. I'm sure it's not easy with a newbie such as myself.
Second, I did try a Catalog Client Script (both onChange and onLoad) and no results. Attempts to debug were pointless as I'm not sure how, nor in my opionion, is it very intuitive.
Here is an image of the onChange Catalog Client Script. Everything I tried produces nothing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 09:00 AM
michael.ritchie - any thoughts on this one? Am I missing something obvious?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 09:56 AM
I noticed in the screenshot above the variable name isn't set. That is required for onChange client scripts to execute.