Try for free Book a demo

Logic App Best practices, Tips, and Tricks: #20 Accessing Runtime Settings (Part II) – Logic App Standard

Microsoft Azure

5 Mins Read

Welcome again to another Logic Apps Best Practices, Tips, and Tricks. In my previous blog posts, I talked about some of the essential best practices you should have while working with Azure Logic Apps. Check out these Logic App tips and tricks!

In my last blog post, I discussed How you could access runtime settings like the Subscription Id or the Resource Group in Logic App Consumption. I mentioned there that this differs from Consumption to Standard since they have different engines. So today, in this second part, we are going to address: How to access runtime settings inside Logic App Standard.

Logic App Standard

Kent Weare did a magnificent blog post about accessing runtime settings in Logic App Standard; you can see:

Accessing Runtime Settings – Logic App Standard

Like in Consumption, when we think about accessing runtime settings in Logic App, our first starting point will be the workflow function. Like in Consumption, this function will return almost all the details about the workflow itself during run time, but the question again is: is it enough?

Unfortunately no! In Consumption, in certain cases, the workflow function provided us with the resource group and the subscription id – you can see and know more about it here– but in Standard, that will not happen. The workflow function will return the same structure as Consumption, but it all includes the following important information:

  • Name of the workflow
  • Run Id
    "id": "/workflows/sfw-Accessing-Runtime-Settings-POC",
    "name": "sfw-Accessing-Runtime-Settings-POC",
    "type": "workflows",
    "run": {
      "id": "/workflows/sfw-Accessing-Runtime-Settings-POC/runs/08585273976656583503297649013CU00",
      "name": "08585273976656583503297649013CU00",
      "type": "workflows/runs"

Once again, taking the same sample from a previous Best practices, Tips and Tricks: to get a friendly error message from our Logic App Standard, we had the need to pass these values to our Azure Function:

  • Subscription Id
  • Resource Group
  • Logic App name -> This property is new and doesn’t exist in the Logic App Consumption
  • Workflow name -> Despite this being a new property, it is the equivalent of the Logic App name in Consumption -> we can get this value using the workflow function
  • and the run id -> we can get this value using the workflow function

Of course, once again, except for the run id, which we always need to grab from the runtime, we can always use Logic App parameters to store this information, but I always question why should I need to do this.

So the main questions here are: Can I get these values in runtime? and if yes, how?

Luckily for us, yes, we can! And unlike what happened in Logic App Consumption, where we need to use different approaches according to our scenario, in Standard, this is quite simple to achieve, and we can always use the same approach.

Because Logic App Standard behind the scenes uses an Azure Web Site, we can take advantage of the appsetting() expression to get environment variables and app settings in Azure App Service. You can read more about the available App environments here: Environment variables and app settings in Azure App Service.

In our case, we are going to use the following:

  • WEBSITE_SITE_NAME: that is the App name; in the context of Logic App Standard, that will be the Logic App Standard app name
  • WEBSITE_OWNER_NAME: This property contains the Azure subscription ID that owns the app, the resource group, and the webspace. At least we need to use this property to get the subscription id and if you want the location.
  • WEBSITE_RESOURCE_GROUP: Azure resource group name that contains the app resource
    • Example: rg-spmsdn-lastd-poc

But you can use more.

So to accomplish this, let’s take an existing workflow and add a Compose action by:

  • Add a new action by clicking on the + New Step button.
  • On the Choose an operation panel, search for Compose and select Data Operations -> Compose action

Logic App JSON message

  • On the Compose action, we are going to create a JSON message with the following values:
    • Let’s start with the simple ones:
      • WorkflowName: workflow()[‘name’] -> This property is the same as Logic App Consumption; the only difference is that in the Logic App Consumption, it represents the Logic App name, and in Standard, it represents the workflow name
      • RunId: workflow()[‘run’][‘name’] -> This property is the same as Logic App Consumption
      • LogicAppName:  appsetting(‘WEBSITE_SITE_NAME’) -> This is a new concept in Logic App Standard
      • ResourceGroup: appsetting(‘WEBSITE_RESOURCE_GROUP’)
        • We can use the split(appsetting(‘WEBSITE_OWNER_NAME’),’+’)[1], but that may be difficult to parse depending on your naming convention.
    • Now the tricky ones:
      • SubscriptionId: split(appsetting(‘WEBSITE_OWNER_NAME’),’+’)[0]– We are parsing the id parameter of the workflow function to get the subscription id
      • Location:
        • If you want the region name to be like a description, for example: “West Europe”, then you can use the following expression: appsetting(‘REGION_NAME’)
        • if you want it to be the “code”, for example: “WestEurope”. Then you need to use this more complex expression: replace(substring(appsetting(‘WEBSITE_OWNER_NAME’), add(lastIndexOf(appsetting(‘WEBSITE_OWNER_NAME’),’-‘),1)), ‘webspace’,”)

You can copy and paste these configurations:

    "Location": "@{replace(substring(appsetting('WEBSITE_OWNER_NAME'), add(lastIndexOf(appsetting('WEBSITE_OWNER_NAME'),'-'),1)), 'webspace','')}",
    "LogicAppName": "@{appsetting('WEBSITE_SITE_NAME')}",
    "ResourceGroup": "@{appsetting('WEBSITE_RESOURCE_GROUP')}",
    "RunId": "@{workflow()['run']['name']}",
    "SubscriptionId": "@{split(appsetting('WEBSITE_OWNER_NAME'),'+')[0]}",
    "WorkflowName": "@{workflow()['name']}"

Logic App Standard

The result will be:

Logic App Result

Stay tuned for the following Logic App Best practices, Tips, and Tricks.

Related reading

This article was published on Feb 3, 2023.

Related Articles