convert JSON.stringgify() to Parse and display a value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 11:10 PM
Hi team, I have one Multi Row variable Set in RITM with help of Script include I am getting those details as below.
Hewlett Packard EliteBook 800 | Operational | In Use | 5CG2134KRM |
HP HP EliteBook 845 G8 Notebook PC | Inventory | Available | 5CG22624QB |
after RITM generation i need to send notification with details of User and Asset model only I used the below email script to fetch a values but user name is getting correct but in place of model it's showing SYSID of that model how can i show the display value?
in script include i'm setting values for Multirow variable set.
Script Include:
email Script:
Notification Preview as below
Associate Name is M Somasekhar
Asset Name [00031a741bb115d478cf54e8624bcbec, 7c892eb41bb915d478cf54e8624bcb0a]
Action Initiated: Sample Catalog
Thanks for your Time and support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2023 01:51 AM
Hi @Somasekhar6 ,
Have you tried using:
var asset = current.variables.user_s_assets.model.getDisplayValue('display_name');
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2023 12:39 PM
Hi @Somasekhar6
It seems like the issue is that you are getting the sys_id of the asset model instead of its display value. To get the display value of the asset model, you need to use getDisplayValue() instead of getValue('sys_id').
Let's update your Script Include to fetch the display values for the model, life cycle stage, life cycle stage status, and serial number:
var listValuename = [];
// Your existing code
while (grasset.next()) {
listValuename.push({
"model": grasset.model.getDisplayValue(),
"life_cycle_stage": grasset.life_cycle_stage.getDisplayValue(),
"life_cycle_stage_status": grasset.life_cycle_stage_status.getDisplayValue(),
"serial_number": grasset.serial_number.getDisplayValue()
});
}
// Rest of your code (if any)
return JSON.stringify(listValuename);
By using getDisplayValue(), you will get the display value for each field instead of the sys_id. With this update, your JSON data will contain the actual names of the model, life cycle stage, life cycle stage status, and serial number.
Additionally, in your email script, you need to loop through the asset list since it's a multi-row variable set. Here's the updated email script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var assets = JSON.parse(current.variables.user_s_assets);
for (var i = 0; i < assets.length; i++) {
var asset = assets[i];
var associate = current.variables.userid.getDisplayValue();
template.print("Associate Name is " + associate);
template.print("<br>");
template.print("Asset Model: " + asset.model);
template.print("<br>");
template.print("Life Cycle Stage: " + asset.life_cycle_stage);
template.print("<br>");
template.print("Life Cycle Stage Status: " + asset.life_cycle_stage_status);
template.print("<br>");
template.print("Serial Number: " + asset.serial_number);
template.print("<br>");
template.print("<br>");
}
})(current, template, email, email_action, event);