Hello!
I've been working on a small project to have a Flow read the contents of a SharePoint list and build a card based on a field (email of the person responsible) to get updates on a few other fields.
After some time digging around on how to build dynamic adaptive cards, I found the way to do it and get responses coming back.
The problem is that as I need to create a dynamic card the "ID" response has to change and as I need more than 1 answer, I append a letter to the beginning of the ID to differentiate each answer.
The result is an object(?) with this structure:
[
{
"M1": "True",
"A1": "Variable Text1",
"M2": "False",
"A2": "Variable Text2"
}
]
and if I append it to an array, I get this structure:
[
{
"M1": "False",
"A1": "Variable Text1",
"M2": "False",
"A2": "Variable Text2",
},
{
"M3": "True",
"A3": "Variable Text3"
}
]
As mentioned before, the ID of the SharePoint list is the number after the A or M in the key. Therefore, what I am trying to do to complete this action and being able to update the list is to:
1) Remove the "M" and "A" from the key
2) Group the values based on the remainder of the key (so for these examples, 1 / 2 / 3) and add the ID field.
Something like:
[
{
"ID":1
"M":"False",
"A":"Variable Text1"
},
{
"ID":2
"M":"False",
"A":"Variable Text2"
},
{
"ID":3
"M":"True",
"A":"Variable Text3"
}
]
Hello! I kept trying new things and instead of using the built array I shared I placed the body of the adaptive card and it seems to work! (likely some kind of data type issue)
Hello again @DamoBird365 ,
I tried your idea but couldn't make it work, however with an apply to each appending the ID as an int to an array I build the missing range array with only the needed numbers
I now came across another issue where changing your code seems to break how it works, but I don't exactly understand how.
After all the process I have my 2 arrays (answers and IDs)
This is the answers array (to simulate the scenario you might notice M3 and A3 are missing, this is already coming from the adaptive card)
This is the ID array which has the same 1/2/4/5 IDs in it from the list
However, when I try to build the select with conditions it gives me an error
InvalidTemplate. The execution of template action 'SelectNewArray' failed: The evaluation of 'query' action 'where' expression '{ "ID": "@int(item())", "M": "@variables('AnswersArray')?[concat('M', item())]", "A": "@variables('AnswersArray')?[concat('A', item())]" }' failed: 'The template language expression 'variables('AnswersArray')?[concat('M', item())]' cannot be evaluated because property 'M1' cannot be selected. Array elements can only be selected using an integer index. Please see https://aka.ms/logicexpressions for usage details.'.
This is the block code:
{
"inputs": {
"from": "@variables('IDArray')",
"select": {
"ID": "@int(item())",
"M": "@variables('AnswersArray')?[concat('M', item())]",
"A": "@variables('AnswersArray')?[concat('A', item())]"
}
}
}
I made some changes on the original one so it points to the IDArray (instead of built range) and instead of the union output for M and A it points to the AnswersArray. I don't understand the error as it seems the error is it can't select M1 but it's there.
Any advice you could share? 😀
Thanks!
I’m away from PC but think you can do a select using the advanced editor. Source is your array, the data is item()?[‘id’].
Should give you an array of numbers.
Damien
Thanks for your reply @DamoBird365! What you suggest does pretty much all of the work I believe, to make it work however I have to transform the IDs from SharePoint instead of expanding a range, in the given example it was from 1 to 3 so the range you suggested worked, however in practice it'd be working with variable numbers and likely not in order.
I've been trying to figure out how to do it but the best I can do is pull them and use a select which leaves them like this (very different to the range your process needs).
Do you know a way to transform this into a range of integers as your process requires?
[
{
"ID": 1
},
{
"ID": 2
},
{
"ID": 3
},
{
"ID": 5
}
]
Sample Input:
Result of Union on First()
Sample Output:
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
P.S. take a look at my new blog here
Hi @LABORSAL
I've assumed that your two objects can be joined using my method, i.e. they come back to your Cloud Flow as seperate objects?
You can join them using Union and FirstExpression and this will create a neat single Array of Keys/Values.
Then if you create a range of answers as an array, in this case 1,2,3 you can pass this to a select and use the values 1,2,3 dynamically to build up a new array using select.
To see it in action, copy and paste the following into a new cloud flow:
{"id":"dcfa8fc7-d817-4111-91e8-a4bf-69cb2f1a","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"DamoBird365_Create_New_Array_from_Two_Objects_Using_Select","operationDefinition":{"type":"Scope","actions":{"Obj1":{"type":"Compose","inputs":[{"M1":"True","A1":"Variable Text1","M2":"False","A2":"Variable Text2"}],"runAfter":{}},"Obj2":{"type":"Compose","inputs":[{"M3":"True","A3":"Variable Text3"}],"runAfter":{"Obj1":["Succeeded"]}},"Union":{"type":"Compose","inputs":"@union(first(outputs('Obj1')),first(outputs('Obj2')))","runAfter":{"Obj2":["Succeeded"]}},"RangeArray":{"type":"Compose","inputs":"@range(1,3)","runAfter":{"Union":["Succeeded"]}},"SelectNewArray":{"type":"Select","inputs":{"from":"@outputs('RangeArray')","select":{"ID":"@item()","M":"@outputs('Union')?[concat('M',item())]","A":"@outputs('Union')?[concat('A',item())]"}},"runAfter":{"RangeArray":["Succeeded"]}}},"runAfter":{}}}
This is what the Cloud Flow looks like:
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
P.S. take a look at my new blog here