Getting string value from an array.Object in Flow designer action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2024 12:36 AM
This is a response I get from an action in flow designer:
This is of the type array.Object
{ "Response": { "temporaryAttachments": [ { "fileName": "Requirement Analysis for Generic ID Creation CHG0092436.docx", "temporaryAttachmentId": "430a93eb-d1e7-4683-8b18-dd3c5731dd83" } ] } }
From this I want to fetch only the temporary attachment ID.
To achieve this I have created another action, which takes input as this from the previous action and given an inline script to fetch the ID from the .Object,
Script:
(function execute(inputs, outputs) {
// Input: array.object containing temporaryAttachments
// Output: string containing temporaryAttachmentId
// Check if the input is valid and contains temporaryAttachments
if (inputs && inputs.Response && inputs.Response.temporaryAttachments) {
// Get the first temporary attachment object
const tempAttachment = inputs.Response.temporaryAttachments[0];
// Check if the temporary attachment object exists
if (tempAttachment && tempAttachment.temporaryAttachmentId) {
// Return the temporary attachment ID as a string
outputs.attachmentId = tempAttachment.temporaryAttachmentId.toString();
} else {
outputs.errorMessage = "Temporary attachment ID not found.";
}
} else {
outputs.errorMessage = "Input does not contain temporary attachments.";
}
})(inputs, outputs);
I have defined the outputs also, although the execution shows successful, the attcahment ID is returing blank.
Kindly help me solve this, or a way to extract the ID from the object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2024 01:15 AM
Hello,
Please change below line and try again.
From:
const tempAttachment = inputs.Response.temporaryAttachments[0];
to:
var tempAttachment = inputs.Response.temporaryAttachments[0];
This worked for me in a background script.
If my answer helps you in any way please mark it as correct or helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2024 01:50 AM
Tried this, but in flow the output is still blank,
Input given:
Logs:
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2024 02:16 AM
Code looks right.
Can you share the screenshots of the output mapping?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2024 02:26 AM
Sure,
Script step output variavles:
Output:
Also Inputs: