getDisplayValue() of reference variable in MRVS from a run script wf activity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 10:03 AM
I am looking to get the display value of two reference variables that are within a MRVS.
MRVS = velocloud_details
Variable 1 = ex_edge_it_manager
Variable 2 = ex_edge_support_group
I've tried simply using current.variables.velocloud_details.ex_edge_it_manager.getDisplayValue() which doesn't work. I've tried the following as well using the script include VariableUtil(). It returns [Object object] in the MRVA log.
var ios = new GlideRecord("item_option_new_set");
ios.get('velocloud_details');
var setID = ios.sys_id;
gs.info("ios log "+setID);
var vu = new VariableUtil();
//var mrva = JSON.parse(vu.getDisplayValue(setID, current.variables.velocloud_details.ex_edge_it_manager));
var mrva = JSON.parse(vu.getDisplayValue('ee2e3f021ba719d027da99ffbd4bcbf8', current.variables.velocloud_details));
gs.info("mrva log " +vu +" " +mrva);
for (var row = 0; row < mrva.length; row++) {
for (var question_name in mrva[row]) {
var displayValue = mrva[row][question_name];
}
gs.info("VELO EDGE "+displayValue);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 10:06 AM
Hi @booher04
The issue with your code is that you are trying to get the display value of a reference variable from a MRVS, but you are not passing the MRVS ID to the getDisplayValue() method. The getDisplayValue() method needs the MRVS ID in order to look up the record in the database and get the display value for the reference variable.
To fix this, you need to pass the MRVS ID to the getDisplayValue() method. You can get the MRVS ID from the current.variables.velocloud_details.sys_id variable.
Here is the updated code:
var ios = new GlideRecord("item_option_new_set");
ios.get('velocloud_details');
var setID = ios.sys_id;
gs.info("ios log "+setID);
var vu = new VariableUtil();
var mrva = JSON.parse(vu.getDisplayValue(setID, current.variables.velocloud_details.ex_edge_it_manager));
gs.info("mrva log " +vu +" " +mrva);
for (var row = 0; row < mrva.length; row++) {
for (var question_name in mrva[row]) {
var displayValue = mrva[row][question_name];
}
gs.info("VELO EDGE "+displayValue);
}
This code will now correctly get the display value of the reference variables from the MRVS.
Here is an explanation of what the code does:
- The first line creates a new GlideRecord object for the item_option_new_set table.
- The second line gets the velocloud_details MRVS from the GlideRecord object.
- The third line gets the MRVS ID from the velocloud_details MRVS.
- The fourth line creates a new instance of the VariableUtil class.
- The fifth line calls the getDisplayValue() method on the VariableUtil object, passing the MRVS ID and the ex_edge_it_manager reference variable.
- The sixth line converts the result of the getDisplayValue() method to a JSON object.
- The seventh line iterates through the rows in the JSON object.
- The eighth line gets the value of the question_name key from the current row.
- The ninth line gets the display value of the reference variable from the current row.
- The tenth line logs the display value of the reference variable.
Please mark the answer as correct solution and helpful if helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 10:43 AM
Wonderful! Thank you for the response and explanation. However, I did try it this way previously and it didn't seem to work, now I just tried it again and here's the log entries for it: