Introduction


In this article, I am going to give a heads-up how the performance degrades when you intend to do every operation inside Logic Apps and also how to leverage our LA performance using Azure Functions.

Scenario


Inside my flow, I need to call an API that outputs JSON. My LA flow should filter and send only the required columns to caller.

Message Structure




Approach 1


In the approach one, I have tried to do everything Inside Logic Apps using Actions.

In the above Logic Apps, after I get the JSON objects I am trying to for each "fields" element and collect
the required field elements. Inside my foreach fields, I am composing a JSON array with list of name fields.
Then using "Compose 2" Action, we create a output JSON and return it. 

In that case, my Logic App has taken average 13-15 seconds. Since it is User facing API, I
have decided to improve the performance from average 13-15 seconds to 2-3 seconds using Azure Functions
and I am quite successful.

My logic app code as below,
{
    "definition": {
        "actions": {
            "Compose_2": {
                "inputs""@{join(outputs('Compose'), ',')}",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type""Compose"
            },
            "For_each": {
                "actions": {
                    "Compose": {
                        "inputs""@item()['name']",
                        "runAfter": {},
                        "type""Compose"
                    }
                },
                "foreach""@body('Get_SF_Objects')?['fields']",
                "runAfter": {
                    "Get_SF_Objects": [
                        "Succeeded"
                    ]
                },
                "type""Foreach"
            },
            "GetSalesforce_Oauth_Access_Token": {
                "inputs": {
                    "body":"grant_type=password&client_id=3MVG9YDQS5WtC11qO_LPE1P5HObJDw_5._0QaidHX5MfGaIQONHgNgVfB5_Vmq.2.yhN6S0nnzLPHASj29g7W&client_secret=8173475474047140117&username=baraneedharan.manoharan%40*****.com&password=****",
                    "headers": {
                        "Content-Type""application/x-www-form-urlencoded"
                    },
                    "method""POST",
                    "uri""https://login.salesforce.com/services/oauth2/token"
                },
                "runAfter": {
                    "Initialize_variable_3": [
                        "Succeeded"
                    ]
                },
                "type""Http"
            },
            "Get_SF_Objects": {
                "inputs": {
                    "headers": {
                        "Authorization""Bearer @{body('GetSalesforce_Oauth_Access_Token')?['access_token']}",
                        "Content-Type""application/json"
                    },
                    "method""GET",
                    "uri""https://ap4.salesforce.com//services/data/v39.0/sobjects/@{variables('ObjectName')}/describe"
                },
                "runAfter": {
                    "GetSalesforce_Oauth_Access_Token": [
                        "Succeeded"
                    ]
                },
                "type""Http"
            },
            "Initialize_variable_3": {
                "inputs": {
                    "variables": [
                        {
                            "name""ObjectName",
                            "type""String",
                            "value""@{json(triggerBody()).ObjectName}"
                        }
                    ]
                },
                "runAfter": {},
                "type""InitializeVariable"
            },
            "Response": {
                "inputs": {
                    "body": {
                        "fields"""
                    },
                    "statusCode": 200
                },
                "runAfter": {
                    "Compose_2": [
                        "Succeeded"
                    ]
                },
                "type""Response"
            }
        },
        "contentVersion""1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {
                        "properties": {
                            "ObjectName": {
                                "type""string"
                            }
                        },
                        "type""object"
                    }
                },
                "kind""Http",
                "type""Request"
            }
        }
    }
}


Approach 2


I have written a Azure function to collect the required fields and create a JSON output message rather using
 compose actions inside my LA.  Now my Logic Apps would like below,



Conclusion


So I have used Azure Functions inside Logic Apps flow and have leveraged the performance that has saved more than 10 seconds of processing time and 1 compose action as well. So please be careful and don't try to do everything using LA Actions that costs performance and as well money.




Return to Top