Using Parameters and Variables in Logic Apps

Using parameters and variables in Workflow Definition Language can be tempting. I already discussed the topic in the following post. The examples are chosen quite randomly, but hopefully they will help you when parameterizing your logic apps.

Using parameters in Logic Apps (basis):

“accountName”: “@parameters(‘customerName’)”
“customerName”: “First name: @{parameters(‘firstName’)} Last name: @{parameters(‘lastName’)}”
By using curly braces, you always return a string, also when the input parameter is of type integer or boolean.

Connection Parameters (no ARM templates):

@parameters(‘$connections’)[‘azureeventgrid’][‘connectionId’]Refers to the $connections in the parameters section within your workflow definition, not in the parameters section at the top. This is an array. [‘azureeventgrid’] is the name of your connection, used as an array index. Each connection has a property connectionId.

For example:
“parameters”: {
“$connections”: {
“value”: {
“azureeventgrid”: {
“id”: “[concat(‘/subscriptions/’,subscription().subscriptionId,’/providers/Microsoft.Web/locations/westeurope/managedApis/azureeventgrid’)]”,
“connectionId”: “[resourceId(‘Microsoft.Web/connections’, parameters(‘EventGridConnectionName’))]”,
“connectionName”: “[parameters(‘EventGridConnectionName’)]”

Using parameters in Logic App expressions:

@concat(‘My age is ‘, string(parameters(‘myAge’)))

Parameters(‘TopicNaam’): o/[project]/[system]/[entity]/[in/out]Parameters(‘SubscriptionName’): logicapp-[o/t/a/p]-sub with logicapp=[system]-[entity]-[protocol]-[in/out][concat(‘/@{encodeURIComponent(encodeURIComponent(”’, parameters(‘TopicNaam’),”’))}/subscriptions/@{encodeURIComponent(”’, parameters(‘SubscriptionNaam’), ”’)}/messages/complete’)]

Double encodeURIComponent statements are needed when the parameter used has url characters like forward slash. I’m not sure whether the ”’ notation is actually needed. Why not use string(parameters(‘TopicNaam’) or not use curly braces for the enclosed encodeURIComponent statement. So, @encodeURIComponent instead of @{encodeURIComponent}.

Using variables without concatenation:

Set Path within an Azure Storage Table Get statement.

Using ResourceId:

[resourceId(parameters(‘ResourceGroup’), ‘Microsoft.EventGrid/topics’,parameters(‘Topic’))][resourceId(subscription().subscriptionId, resourceGroup().name, ‘Microsoft.Logic/workflows’, parameters(‘logicAppNaam’))][resourceId(‘Microsoft.Web/connections’, parameters(‘EGTopicConnectionNaam’))]Function ResourceId returns the unique identifier of a resource. You use this function when the resource name is ambiguous or not provisioned within the same template. Can be used at the
scope of the subscription, resource group or resource(type).

Deriving variables from parameters:

“MessageCreatorFunction”: “[concat(‘[function_name]’, parameters(‘OTAPEnvironment’),’-afu’)]”
Derive the function name from the environment, instead of using a parameter that defines the environment specific function name.