How the get one of the values in the output array from previous in-line code action?

506 Views Asked by At

I use in-line code action to get the user's info and return an array, now i want to get the email address and the name to send an email.

I tried the expression: Outputs('action name')[1], but it shows that the template is invalid.

Thank You!

How can i get the values(name and email address) in this array?

2

There are 2 best solutions below

0
BrunoLucasAzure On

to get a specific field of one array element you can use this:

variables('MyArray')?1?['Email_Address']

Where MyArray is the name of the Array Variable:

enter image description here

1 is the array element position and [Email_Address] the element field

Considering the Array:

[
  {
    "Email_Address": "[email protected]",
    "Email_Address2": "[email protected]",
    "Email_Address3": "[email protected]"
  },
  {
    "Email_Address": "[email protected]",
    "Email_Address2": "[email protected]",
    "Email_Address3": "[email protected]"
  }
]

variables('MyArray')?1?['Email_Address'] will result in:

enter image description here

But are you sure the value you need will always be in the same place? is the array always the same amount of items?

maybe you may find better alternatives with an Array filter. https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-perform-data-operations?tabs=consumption#filter-array-action?WT.mc_id=AZ-MVP-5005174

0
RithwikBojja On

I do agree with @BrunoLucasAzure, And assuming your output from Inline code will be something like:

[{
"Email_Address":"[email protected]",
"name":"Rithwik"
}]

Now firstly you need to set the output to a variable or initialize it to a variable then you can use below steps:

variables('emo')[0]['name']

enter image description here

Output:

enter image description here

If you want email address then use:

variables('emo')[0]['Email_Address']

enter image description here

Output:

enter image description here