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.
Solved! Go to Solution.
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):
(2) The CHEmployee array contains two employees: Elsa and Edwin (or two JSON objects).
(3) We can use the Select action to select all the employee names from CHEmployee:
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):
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.
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):
(2) The CHEmployee array contains two employees: Elsa and Edwin (or two JSON objects).
(3) We can use the Select action to select all the employee names from CHEmployee:
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):
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.
Please click the icon to switch the mode to text mode:
Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.
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"
After this, I'm using Select to take these values and then put them into an Append to array variable
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.
What am I doing wrong here?
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
While it didn't error, the result doesn't seem to be an Array
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.'.
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:
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.
@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.
I'm trying to get the final output to be just '2022-09-30', as that is date difference.
item() will refer to the current item as the Filter Array action loops through all the values in the DateArray:
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.
User | Count |
---|---|
101 | |
36 | |
29 | |
24 | |
16 |
User | Count |
---|---|
132 | |
54 | |
53 | |
37 | |
26 |