How do we get the display value of reference cells in the multi-row variable set? i.e instead of displaying the sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 03:28 AM
How do we get the display value of reference fields in the multi-row variable set? i.e instead of displaying the sys_id.
I tried getDisplayValue() but it is giving as undefined.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2019 05:55 AM
The 'simplest' way is to call on a method within the script include VariableUtils, and you will need to pass the sys ID of the variable set, along with the multi-row variable object, as parameters. For the sys_id, normally you'd be able to use getGlideObject on the variable, but that doesn't return anything for multi-row variable sets.
The variable set lives on item_option_new_set, so you can look for the variable name there in the internal_name field to get the sys_id:
var ios = new GlideRecord("item_option_new_set");
ios.get("internal_name", mrvs_name);
var setID = ios.sys_id;
(Variable names, set or non-set, should be unique)
For the variable itself, that would just be current.variables.mrvs_name. So with that you can call on VariableUtils to get the display values in one swoop:
var vu = new VariableUtil();
var mrva = JSON.parse(vu.getDisplayValue(setID, current.variables.mrvs_name));
Then you can step through mrva (Multi-Row Variable Answers), which is an array of objects. Each array element is a row, and each row contains a name:value pair -- the name being the question variable name, and the value being the display value of the answer.
for (var row = 0; row < mrva.length; row++) {
for (var question_name in mrva[row]) {
var displayValue = mrva[row][question_name];
}
}
You'll need to do more work to get the question label, and to sort them in the same order as shown within the MRV and on the form itself, and so on. Later today or tomorrow I'll be putting up the code I'm using to compose both HTML emails for approvals along with a plaintext output for catalog task or record producer descriptions - the code has to work for any catalog item, so hard-coding the names of various MRVS is a non-starter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 08:32 AM
This is VERY helpful. Were you able to get it working for the plaintext output for catalog task or record producer descriptions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 12:11 PM - edited 12-07-2022 12:12 PM
It did work, yes. It's been a couple years since I've worked on the instance this was deployed on. The target record must have copies of the variable (catalog task). Record producers - as long as you have a record to read with catalog variables in it, there shouldn't be any issue with printing it to a sufficiently spacious text field on some other (non-catalog / task) table.
The post is here:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2019 04:22 AM
Is there a way to do this without scripting? I'm trying to build a report to show the values in the mrvs and for the reference fields, it's showing the sys_id instead of the display value. My SNow setup is controlled by a central office and I don't have access to any server side functions, such as script includes, email notifications and the like. Is there a no-code way to show the display values in a report?