Search code examples
azure-logic-appspower-automatepower-platform

Logic APP - For Each from a Filtered Array - retrieve Object ID trough API


I'm trying to create a loop, but I cant seem to get it to work. I filter a sharepoint list and have the below output as a result.

Next I want to loop over the 2 Ad groups and get their Object ID back. For some reason I cannot seem to get the correct reference.

I tried multiple things, this is the last one I tried:

What expressions do I need to retreive the AD group name?

enter image description here

{
    "body": [
        {
            "@odata.etag": "\"4\"",
            "ItemInternalId": "1",
            "ID": 1,
            "Title": "Access Rights",
            "ReportName": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                "Id": 4,
                "Value": "WOL Campaign Report"
            },
            "Environment#Id": 1,
            "Azure_x0020_AD_x0020_Group": "PT_PBI_TST_AR_WOLCAMPAIGN_APPViewer",
            "Modified": "2022-01-14T16:30:47Z",
            "Created": "2022-01-13T23:56:02Z",
            "Author": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "",
                "DisplayName": "",
                "Email": "",
                "Picture": ""
            },
            "Author#Claims": "",
            "Editor": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "",
                "DisplayName": "",
                "Email": "",
                "Picture": ""
            }
        },
        {
            "@odata.etag": "\"1\"",
            "ItemInternalId": "4",
            "ID": 4,
            "Title": "66",
            "ReportName": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                "Id": 4,
                "Value": "WOL Campaign Report"
            },
            "Environment#Id": 1,
            "Azure_x0020_AD_x0020_Group": "PT_PBI_TST_RLS_WOLCAMPAIGN_AdminViewer",
            "Modified": "2022-01-14T16:32:00Z",
            "Created": "2022-01-14T16:32:00Z",
            "Author": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "",
                "DisplayName": "",
                "Email": "",
                "Picture": ""
            },
            "Author#Claims": "",
            "Editor": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "",
                "DisplayName": "",
                "Email": "",
                "Picture": ""
            }
        }
    ]
}

Solution

  • You shouldn't actually need to write any specific expression, the standard dynamic content should give you what you need.

    If you use the Parse JSON action, it will make life a lot easier. I can't tell if you are or not but it looks little different to my example.

    Flow

    However, in the template (based on what I've put together) this is the expression that the dynamic content WYSIWYG editor generates ...

    @items('For_Each_Item_on_Body')?['Azure_x0020_AD_x0020_Group']
    

    You can import this JSON template (Code View) into you tenant for testing.

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "For_Each_Item_on_Body": {
                    "actions": {
                        "Set_variable": {
                            "inputs": {
                                "name": "Azure AD Group",
                                "value": "@items('For_Each_Item_on_Body')?['Azure_x0020_AD_x0020_Group']"
                            },
                            "runAfter": {},
                            "type": "SetVariable"
                        }
                    },
                    "foreach": "@body('Parse_JSON')?['body']",
                    "runAfter": {
                        "Initialize_Azure_AD_Group_Variable": [
                            "Succeeded"
                        ]
                    },
                    "type": "Foreach"
                },
                "Initialize_Azure_AD_Group_Variable": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "Azure AD Group",
                                "type": "string"
                            }
                        ]
                    },
                    "runAfter": {
                        "Parse_JSON": [
                            "Succeeded"
                        ]
                    },
                    "type": "InitializeVariable"
                },
                "Parse_JSON": {
                    "inputs": {
                        "content": {
                            "body": [
                                {
                                    "Author": {
                                        "Claims": "",
                                        "DisplayName": "",
                                        "Email": "",
                                        "Picture": "",
                                        "odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
                                    },
                                    "Author#Claims": "",
                                    "Azure_x0020_AD_x0020_Group": "PT_PBI_TST_AR_WOLCAMPAIGN_APPViewer",
                                    "Created": "2022-01-13T23:56:02Z",
                                    "Editor": {
                                        "Claims": "",
                                        "DisplayName": "",
                                        "Email": "",
                                        "Picture": "",
                                        "odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
                                    },
                                    "Environment#Id": 1,
                                    "ID": 1,
                                    "ItemInternalId": "1",
                                    "Modified": "2022-01-14T16:30:47Z",
                                    "ReportName": {
                                        "Id": 4,
                                        "Value": "WOL Campaign Report",
                                        "odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
                                    },
                                    "Title": "Access Rights",
                                    "odata.etag": "\"4\""
                                },
                                {
                                    "Author": {
                                        "Claims": "",
                                        "DisplayName": "",
                                        "Email": "",
                                        "Picture": "",
                                        "odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
                                    },
                                    "Author#Claims": "",
                                    "Azure_x0020_AD_x0020_Group": "PT_PBI_TST_RLS_WOLCAMPAIGN_AdminViewer",
                                    "Created": "2022-01-14T16:32:00Z",
                                    "Editor": {
                                        "Claims": "",
                                        "DisplayName": "",
                                        "Email": "",
                                        "Picture": "",
                                        "odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser"
                                    },
                                    "Environment#Id": 1,
                                    "ID": 4,
                                    "ItemInternalId": "4",
                                    "Modified": "2022-01-14T16:32:00Z",
                                    "ReportName": {
                                        "Id": 4,
                                        "Value": "WOL Campaign Report",
                                        "odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"
                                    },
                                    "Title": "66",
                                    "odata.etag": "\"1\""
                                }
                            ]
                        },
                        "schema": {
                            "properties": {
                                "body": {
                                    "items": {
                                        "properties": {
                                            "Author": {
                                                "properties": {
                                                    "Claims": {
                                                        "type": "string"
                                                    },
                                                    "DisplayName": {
                                                        "type": "string"
                                                    },
                                                    "Email": {
                                                        "type": "string"
                                                    },
                                                    "Picture": {
                                                        "type": "string"
                                                    },
                                                    "odata.type": {
                                                        "type": "string"
                                                    }
                                                },
                                                "type": "object"
                                            },
                                            "Author#Claims": {
                                                "type": "string"
                                            },
                                            "Azure_x0020_AD_x0020_Group": {
                                                "type": "string"
                                            },
                                            "Created": {
                                                "type": "string"
                                            },
                                            "Editor": {
                                                "properties": {
                                                    "Claims": {
                                                        "type": "string"
                                                    },
                                                    "DisplayName": {
                                                        "type": "string"
                                                    },
                                                    "Email": {
                                                        "type": "string"
                                                    },
                                                    "Picture": {
                                                        "type": "string"
                                                    },
                                                    "odata.type": {
                                                        "type": "string"
                                                    }
                                                },
                                                "type": "object"
                                            },
                                            "Environment#Id": {
                                                "type": "integer"
                                            },
                                            "ID": {
                                                "type": "integer"
                                            },
                                            "ItemInternalId": {
                                                "type": "string"
                                            },
                                            "Modified": {
                                                "type": "string"
                                            },
                                            "ReportName": {
                                                "properties": {
                                                    "Id": {
                                                        "type": "integer"
                                                    },
                                                    "Value": {
                                                        "type": "string"
                                                    },
                                                    "odata.type": {
                                                        "type": "string"
                                                    }
                                                },
                                                "type": "object"
                                            },
                                            "Title": {
                                                "type": "string"
                                            },
                                            "odata.etag": {
                                                "type": "string"
                                            }
                                        },
                                        "required": [
                                            "odata.etag",
                                            "ItemInternalId",
                                            "ID",
                                            "Title",
                                            "ReportName",
                                            "Environment#Id",
                                            "Azure_x0020_AD_x0020_Group",
                                            "Modified",
                                            "Created",
                                            "Author",
                                            "Author#Claims",
                                            "Editor"
                                        ],
                                        "type": "object"
                                    },
                                    "type": "array"
                                }
                            },
                            "type": "object"
                        }
                    },
                    "runAfter": {},
                    "type": "ParseJson"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "Recurrence": {
                    "evaluatedRecurrence": {
                        "frequency": "Month",
                        "interval": 3
                    },
                    "recurrence": {
                        "frequency": "Month",
                        "interval": 3
                    },
                    "type": "Recurrence"
                }
            }
        },
        "parameters": {}
    }
    

    This is the result I get within the loop for the two items in the array ...

    Result Item 1

    Item 1

    Result Item 2

    Item 2