cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IPC_ahaas
Responsive Resident
Responsive Resident

Append to Array Variable Results in String

I have an Array called "AllChipTransactions" with data like this:

 

 

[
  {
    "Employee": "Elsa",
    "Culture Chips": "1",
    "Culture Value": "Respect - Do Right",
    "Safety Chips": null,
    "Safety Value": null,
    "Notes": "For always having the availability to follow the instruction given to me.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:25 PM"
  },
  {
    "Employee": "Edwin",
    "Culture Chips": null,
    "Culture Value": null,
    "Safety Chips": "1",
    "Safety Value": "Supervisor and Team Lead Engagement",
    "Notes": "For being aware of your safety and that of others.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:26 PM"
  }

 

 

 

I have another Array called "CHEmployees" like this

 

 

[
  {
    "Employee": "Elsa",
    "EmployeeID": "7130M"
  },
  {
    "Employee": "Edwin",
    "EmployeeID": "7260M"
  }
]

 

 

 

I use "Apply to each" for "AllChipTransactions" and if the "Employee" is found in the "CHEmployees" array,

it uses "Append to Array variable" all the values of "AllChipTransactions" to "CHChipTransactions".

 

 

"Employee": @{items('Apply_to_each')?['Employee']},
"Culture Chips": @{items('Apply_to_each')?['Culture Chips']},
"Culture Value": @{items('Apply_to_each')?['Culture Value']},
"Safety Chips": @{items('Apply_to_each')?['Safety Chips']},
"Safety Value": @{items('Apply_to_each')?['Safety Value']},
"Notes": @{items('Apply_to_each')?['Notes']},
"Grantor": @{items('Apply_to_each')?['Grantor']},
"Date": @{items('Apply_to_each')?['Date']}

 

 

 

The result looks like this:

 

 

[
  "\"Employee\": Elsa,\n\"Culture Chips\": 1,\n\"Culture Value\": Attitude - We Take Responsiblity,\n\"Safety Chips\": ,\n\"Safety Value\": ,\n\"Notes\": For always having the availability to follow the instruction given to me.,\n\"Grantor\": Hector Rivera,\n\"Date\": Sep 13 03:51 AM",
  "\"Employee\": Edwin,\n\"Culture Chips\": 1,\n\"Culture Value\": Attitude - Team,\n\"Safety Chips\": ,\n\"Safety Value\": ,\n\"Notes\": For being aware of your safety and that of others.,\n\"Grantor\": Vivaldo Luis,\n\"Date\": Sep 13 07:39 AM"
]

 

 

 

This is causing issues, as am I trying to loop through "CHChipTransactions" and it's saying it's a String not an Array. I'm thinking my "Append to Array variable" format is wrong.

1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Super User
Super User

Hi @IPC_ahaas ,

 

The append to array action needs to create a JSON array - after which you can iterate over it using the Apply to Each loop.

 

Here is one method that you could use.

 

(1) AllChipTransactions array contains three employee records Elsa, Edwin and Ellis (i.e three JSON objects):

Snag_4c03137.png

(2) The CHEmployee array contains two employees: Elsa and Edwin (or two JSON objects).

Snag_4c089f5.png

 

(3) We can use the Select action to select all the employee names from CHEmployee: 

Snag_4bdacaf.png

The output of the Select action is an array containing employee names:

 

[
  "Elsa",
  "Edwin"
]

 

 

(4) We can then use the filter array action. This will iterate over all the records (items) in AllChipTransactions and select only those employee records whose name is found in the array produced by Select action (the body('Select') dynamic content):

Snag_4be2327.png

This is the runtime output of the filter array action, containing the records for Elsa and Edwin only:

 

[
  {
    "Employee": "Elsa",
    "Culture Chips": "1",
    "Culture Value": "Respect - Do Right",
    "Safety Chips": null,
    "Safety Value": null,
    "Notes": "For always having the availability to follow the instruction given to me.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:25 PM"
  },
  {
    "Employee": "Edwin",
    "Culture Chips": null,
    "Culture Value": null,
    "Safety Chips": "1",
    "Safety Value": "Supervisor and Team Lead Engagement",
    "Notes": "For being aware of your safety and that of others.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:26 PM"
  }
]

 

 

Hope this helps.

 


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

11 REPLIES 11
ekarim2020
Super User
Super User

Hi @IPC_ahaas ,

 

The append to array action needs to create a JSON array - after which you can iterate over it using the Apply to Each loop.

 

Here is one method that you could use.

 

(1) AllChipTransactions array contains three employee records Elsa, Edwin and Ellis (i.e three JSON objects):

Snag_4c03137.png

(2) The CHEmployee array contains two employees: Elsa and Edwin (or two JSON objects).

Snag_4c089f5.png

 

(3) We can use the Select action to select all the employee names from CHEmployee: 

Snag_4bdacaf.png

The output of the Select action is an array containing employee names:

 

[
  "Elsa",
  "Edwin"
]

 

 

(4) We can then use the filter array action. This will iterate over all the records (items) in AllChipTransactions and select only those employee records whose name is found in the array produced by Select action (the body('Select') dynamic content):

Snag_4be2327.png

This is the runtime output of the filter array action, containing the records for Elsa and Edwin only:

 

[
  {
    "Employee": "Elsa",
    "Culture Chips": "1",
    "Culture Value": "Respect - Do Right",
    "Safety Chips": null,
    "Safety Value": null,
    "Notes": "For always having the availability to follow the instruction given to me.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:25 PM"
  },
  {
    "Employee": "Edwin",
    "Culture Chips": null,
    "Culture Value": null,
    "Safety Chips": "1",
    "Safety Value": "Supervisor and Team Lead Engagement",
    "Notes": "For being aware of your safety and that of others.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:26 PM"
  }
]

 

 

Hope this helps.

 


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

Your Select doesn't have an "Enter value" to the right of "item()?['Employee']". When I choose Select, I have to enter a value to the right of it.

IPC_ahaas_0-1663964751221.png

 

Please click the icon to switch the mode to text mode:

Snag_54bbf0b.png


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

IPC_ahaas
Responsive Resident
Responsive Resident

This looks to be working with an Array, but I'm having trouble with the step before this now.

 

Using Get items for a SharePoint List, it has multiple Columns.

Employee,
CoreChips,
CoreValue,
SafetyChips,
SafetyValue,
Notes,
Grantor,
Created

 

I am trying to combine two sets of fields into one ("CoreChips" & "SafetyChips" -> "ChipQuantity") and ("CoreValue" & "SafetyValue" -> "ChipValue") while adding "ChipQuantity"

IPC_ahaas_0-1664195740846.png

 

After this, I'm using Select to take these values and then put them into an Append to array variable

IPC_ahaas_1-1664195936387.png

 

But the error I get is:

BadRequest. The 'from' property value in the 'select' action inputs is of type 'Object'. The value must be an array.

IPC_ahaas_2-1664196054167.png

 

What am I doing wrong here?

IPC_ahaas
Responsive Resident
Responsive Resident

I've tried putting the Get items (Value) into an Array first, then using Apply to each for that and then using Select within it, but I get the same error.

 

So then I tried using Append to array variable without using Select by specifying each value individually

IPC_ahaas_1-1664199430164.png

 

While it didn't error, the result doesn't seem to be an Array

IPC_ahaas_2-1664199461447.png

 

 

 

IPC_ahaas
Responsive Resident
Responsive Resident

In fact, I know it's not an Array because when I use the Filter later it says 

InvalidTemplate. The execution of template action 'Filter_AllChipTransactions_for_CH' failed: The evaluation of 'query' action 'where' expression '@contains(body('Select_CHEmployees'), item()?['Employee'])' failed: 'The template language expression 'contains(body('Select_CHEmployees'), item()?['Employee'])' cannot be evaluated because property 'Employee' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

IPC_ahaas_0-1664204588633.png

IPC_ahaas_1-1664204604479.png

 

 

ekarim2020
Super User
Super User

In the Append to AllCHipTransactions action, surround the values with { }. This is because the array needs to be an array of JSON objects, and the append action needs to append a single JSON object:

IPC_ahaas_1-1664199430164.png

For example:

 

  {
    "Employee": "Elsa",
    "Culture Chips": "1",
    "Culture Value": "Respect - Do Right",
    "Safety Chips": null,
    "Safety Value": null,
    "Notes": "For always having the availability to follow the instruction given to me.",
    "Grantor": "Vivaldo",
    "Date": "Sep 12 03:25 PM"
  }

 

 


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

 

Wow, I swore I had that before and got a different error. Thank you.

IPC_ahaas
Responsive Resident
Responsive Resident

@ekarim2020 I have a completely different flow that I need to do the same thing with now. Not sure how to do it if the array items don't have names.

IPC_ahaas_1-1664394478748.png

 

I'm trying to get the final output to be just '2022-09-30', as that is date difference.

IPC_ahaas_0-1664394452655.png

 

ekarim2020
Super User
Super User

item() will refer to the current item as the Filter Array action loops through all the values in the DateArray:

 

Snag_40e48c.png


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up. 

 

You're a lifesaver @ekarim2020 . I had the values flipped. This now works exactly as intended. Thank you.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Users online (2,855)