Using script to transform a field value output in flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 04:40 AM
I have written this code to transform additional info but the line var key in additional info is printing nothing when I'm trying to see what's coming in key.
function transformPayload(additionalInfo) {
const formattedPayload = {};
for (var key in additionalInfo) {
var newKey = key.replace(/flattened\.alarmMetaData\.0\./g, '');
formattedPayload[newKey] = additionalInfo[key];
}
return formattedPayload;
}
const severity = mapObj(fd_data.look_up_record.record.severity);
const alertNum = fd_data.look_up_record.record.number;
const ciorNode = fd_data.look_up_record.record.node;
const alertType = fd_data.look_up_record.record.type.name;
const alertSource = fd_data.look_up_record.record.source;
const additionalInfo = fd_data.look_up_record.record.additional_info;
const parsedAdditionalInfo = JSON.parse(additionalInfo);
const rawMetricName = parsedAdditionalInfo["flattened.alarmMetaData.0.query"];
const regex = /^[a-zA-Z]*\b/;
const metricName = regex.exec(rawMetricName)[0];
const alarmSummary = parsedAdditionalInfo["flattened.alarmMetaData.0.alarmSummary"];
const region = parsedAdditionalInfo["flattened.alarmMetaData.0.dimensions.0.region"];
const resourceId = parsedAdditionalInfo["resourceId"];
const resourceType = parsedAdditionalInfo["resourceType"];
const responseBlock = transformPayload(parsedAdditionalInfo);
return actualResponse;
Additional info looks like below
{
"flattened.alarmMetaData.0.dimensions.0.deploymentId":
"Xyz",
"flattened.alarmMetaData.0.dimensions.0.deploymentName": "source",
"flattened.alarmMetaData.0.dimensions.1.deploymentId": "abc",
"flattened.alarmMetaData.0.dimensions.1.deploymentName": "target",
"flattened.alarmMetaData.0.dimensions.2.deploymentId":
"Fgh",
......
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 03:42 PM
Hi, unfortunately your post does not make your payload source clear.
Perhaps you could update this thread with details of your payload and the script that calling transformPayload and passing in additionalInfo, so that the community can better understand the type and content of additionalInfo when it is passed to the function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 09:08 AM
So I'm using this script in a flow designer subflow. We have a subflow that creates incidents from alerts. So the description label of the action "Create Task" is scripted and we're using the above mentioned script to populate a custom message in description. Below is the script:
function transformPayload(additionalInfo) {
const formattedPayload = {};
for (var key in additionalInfo) {
var newKey = key.replace(/flattened\.alarmMetaData\.0\./g, '');
formattedPayload[newKey] = additionalInfo[key];
}
return formattedPayload;
}
const additionalInfo = fd_data.look_up_record.record.additional_info;
const response = transformPayload(additionalInfo);
return response;
Below is how the additionalInfo playload looks like:
{
"flattened.alarmMetaData.0.dimensions.0.deploymentId":"Xyz",
"flattened.alarmMetaData.0.dimensions.0.deploymentName": "source",
"flattened.alarmMetaData.0.dimensions.1.deploymentId": "abc",
"flattened.alarmMetaData.0.dimensions.1.deploymentName": "target",
"flattened.alarmMetaData.0.dimensions.2.deploymentId":"Fgh",
......
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 09:30 AM
Hey, can you check this, normally fd_data._1__look_up_record_1 or fd_data._2__look_up etc depending on the line where lookup record being called..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 11:18 AM - edited 05-20-2024 11:20 AM
Yeah sorry about that, I already have this line
I have also noticed one more thing is that the additionalInfo is an object but the key when I iterate over additionalInfo is also an object.