Pass trough all SharePoint items from the “Get Items” action in Azure Logic Apps

When constructing a Logic Apps that gets information from a SharePoint list you will use the SharePoint “Get Items” action. This action allows you to get items from a SharePoint list you connect the action to. You can then process the items by using for example an Azure Function. Constructing a flow this will give you the following Logic App.

image

By default Logic Apps will construct a foreach loop after the “Get Items” action that you cannot see in the designer view. By opening the code view you will see it (It will only appear if you added a value of the “Get Items” action to for example the input of the Azure Function).

{
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2015-08-01-preview/workflowdefinition.json#",
    "actions": {
        "Get_items": {
            "conditions": [],
            "inputs": {
                "host": {
                    "api": {
                        "runtimeUrl": "https://logic-apis-westeurope.azure-apim.net/apim/sharepointonline"
                    },
                    "connection": {
                        "name": "@parameters('$connections')['sharepointonline_1']['connectionId']"
                    }
                },
                "method": "get",
                "path": ""
            },
            "type": "apiconnection"
        },
        "SharePointProcessing": {
            "conditions": [
                {
                    "dependsOn": "Get_items"
                }
            ],
            "foreach": "@body('Get_items')['value']",
            "inputs": {
                "body": "@item()['Status']",
                "function": {
                    "id": ""
                }
            },
            "type": "Function"
        }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {
        "$connections": {
            "defaultValue": {},
            "type": "Object"
        }
    },
    "triggers": {
        "recurrence": {
            "recurrence": {
                "frequency": "Hour",
                "interval": 1
            },
            "type": "Recurrence"
        }
    }
}

This means that the Azure Function will be called for every item that is retrieved by the “Get Items” action meaning that if the action retrieves 100 items the function will be started 100 times.

In a Logic App a colleague (Andre de Ruiter) of mine was constructing he wanted to process all the items at ones in a Azure Function. By default this isn’t possible because the Logic Apps designer only gives you the option to add specific fields into the input value.

image

As you can see in the above screenshots the action retrieved all the fields available on the SharePoint item and does not give a option to add the complete body of the “Get Items” action.

If you want to send the complete body trough you will have to use de code view. The easiest way is to add one output from the “Get Items” activity into the input of your action and then click on “Code View”.

Within this view search for the Azure Function or the other action that is being called. You will notice that this action contains the foreach object.

"SharePointProcessing": {
    "conditions": [
        {
            "dependsOn": "Get_items"
        }
    ],
    "foreach": "@body('Get_items')['value']",
    "inputs": {
        "body": "@item()['Deleted']",
        "function": {
            "id": ""
        }
    },
    "type": "Function"
}

Remove the line with the foreach and in the “inputs” object change the body value to: “@body(‘Get_items’)”. Your action will know look as followed.

"SharePointProcessing": {
    "conditions": [
        {
            "dependsOn": "Get_items"
        }
    ],
    "inputs": {
        "body": "@body('Get_items')",
        "function": {
            "id": ""
        }
    },
    "type": "Function"
}

Open the “Designer” again and notice that the Action now contains the “body” element of the “Get Items” action.

image

Related Posts

Azure Managed Service Identity and Local Development Instead of storing user credentials of an external system in a configuration file, you should store them in the Azure Key Vault. Before MSI (Managed S...
The securitydata Azure resource group Most of the times companies have rules in place for managing their Azure environment. The main rules that should be in place are “Azure Policies” and ...
Point to Site VPN Client won’t install To connect an Azure App Service to a on-premise database you can make use of different solutions. Two of those solutions are: Hybrid Connection ...
Invoke Azure Function in your Visual Studio Team Services CI/CD pipeline A utility task is available for Visual Studio Team Services (VSTS) to invoke an http triggered Azure function. The ability to invoke a Function from y...
VSTS Extension for Azure Role Based Access Control Today I published an extension for Visual Studio Team Services (VSTS) that gives you the ability to add and remove role based access assignments in Az...
Listing Azure Services within a CSV file In some situations you will look into a current Azure Environment and the setup/governance of it and need to migrate or move resources around. The ...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.