cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LABORSAL
Advocate II
Advocate II

PowerAutomate Adaptive Cards + Teams + SharePoint List Read/Write

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"
  }
]

 

1 ACCEPTED SOLUTION

Accepted Solutions

Sample Input:

 

DamoBird365_1-1619075236183.png

 

Result of Union on First()

 

DamoBird365_2-1619075270332.png

 

Sample Output:

 

DamoBird365_0-1619075209017.png

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

View solution in original post

6 REPLIES 6
DamoBird365
Super User
Super User

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:

 

HowToCopyPasteSolution.gif

 

{"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:

DamoBird365_0-1619075131672.png

 

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

 

Sample Input:

 

DamoBird365_1-1619075236183.png

 

Result of Union on First()

 

DamoBird365_2-1619075270332.png

 

Sample Output:

 

DamoBird365_0-1619075209017.png

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

View solution in original post

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
  }
]

 

DamoBird365
Super User
Super User

@LABORSAL 

 

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

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)

LABORSAL_1-1619450894401.png

 

This is the ID array which has the same 1/2/4/5 IDs in it from the list

LABORSAL_2-1619451004666.png

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!

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)

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Top Kudoed Authors
Users online (2,255)