Getting string value from an array.Object in Flow designer action

Hussain Marakar
Tera Contributor

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.

8 REPLIES 8

Ahh i think below is your issue.

VishwaPandya19_0-1713433155887.png

VishwaPandya19_1-1713433243071.png

 

in the output mapping Label is "attachmentId" but name is "attachmentid".
In the code you are using the label instead of the name which might be causing the output to not pass.

Please update and test.

 

If my answer helps you in any way please mark it as correct or helpful.

Tried the same,

HussainMarakar_0-1713434101460.png



But still returning empty:

HussainMarakar_1-1713434147528.png

HussainMarakar_2-1713434158871.png

Still not sure why empty is returned, have tried most of the methods!
Kindly help,
Your assistance is very much appreciated!

You've shown the Action Inputs, but they're not expanded. Have you specified the structure of the object in the child configuration?

 

Also what about the Script Step input variables?

Shree_G
Mega Sage

Hello @Hussain Marakar ,

 

This worked for me. I tried to replicate the action in my PDI and did some tweaks as below :

 

Inputs : type changed to JSON

Shree_G_0-1746774993299.png

 

Script : Make sure you are using correct input parameter name :

Shree_G_1-1746775087275.png

 

(function execute(inputs, outputs) {

var jsonTempAttach = JSON.parse(inputs.parameter);

if (jsonTempAttach.Response.temporaryAttachments[0]) {

var tempAttachment = jsonTempAttach.Response.temporaryAttachments[0];

if (tempAttachment && tempAttachment.temporaryAttachmentId) {

outputs.attachmentid = tempAttachment.temporaryAttachmentId.toString();
} else {
outputs.errormessage = "Temporary attachment ID not found.";
}
} else {
outputs.errormessage = "Input does not contain temporary attachments.";
}
})(inputs, outputs);

 

Output :

Shree_G_2-1746775139594.png

 

 

 


If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.