How to use values passed in HTTP Request in Logic Apps / Assign Values to Logic App Parameters Dynamically - azure

I am trying to make a generic Logic App(LA) to do some processing on some files. Calling the Logic App from ADF and able to pass the correct File Names. However I am not able to use/assign values passed to the Logic App to the parameters defined in the LA. What am I Missing ? Please see the screenshot.
-Thanks
Sample Execution to show the names are passed properly.

As far as I know, we can't assign PRM_FileName from the body of the request to one parameter. But we can use expression to get the value of PRM_FileName.
The expression should be triggerBody()?['PRM_FileName']. You can also assign PRM_FileName to a variable (for example named var1) and you can use the var1 in your next actions but not use the expression(shown as below screenshot).
============================Update===========================
Below is my logic app:
I did everything what you mentioned in your 3 steps except I put the PRM_FileName in the body of the request but not appending it at the end of url.
============================Update 2===========================
Please use same schema with mine:
{
"type": "object",
"properties": {
"PRM_FileName": {
"type": "string"
}
}
}
And then select the PRM_FileName into the variable directly(shown as below screenshot).
The expression should be triggerBody()?['PRM_FileName'], but in your screenshot the expression is triggerOutputs()['queries']['PRM_FileName'].

Related

Get value from json in LogicApp

Rephrasing question entirely, as first attempt was unclear.
In my logic app I am reading a .json from blob which contains:
{
"alpha": {
"url": "https://linktoalpha.com",
"meta": "This logic app does job aaaa"
},
"beta": {
"url": "https://linktobeta.com",
"meta": "This logic app does job beta"
},
"theta": {
"url": "https://linktotheta.com",
"meta": "This logic app does job theta"
}
}
I'm triggering the logic app with a http post which contains in the body:
{ "logicappname": "beta" }
But the value for 'logicappname' could be alpha, beta or theta. I now need to set a variable which contains the url value for 'beta'. How can this be achieved without jsonpath support?
I am already json parsing the file contents from the blob and this IS giving me the tokens... but I cannot see how to select the value I need. Would appreciate any assistance, thank you.
For your requirement, I think just use "Parse JSON" action to do it. Please refer to the steps below:
1. I upload a file testJson.json to my blob storage, then get it and parse it in my logic app.
2. We can see there are three url in the screenshot below. As you want to get the url value for beta, it is the second one, so we can choose the second one.
If you want to get the url value by the param logicappname from the "When a HTTP request is received" trigger, you can use a expression when you create the result variable.
In my screenshot, the expression is:
body('Parse_JSON')?[triggerBody()?['logicappname']]?['url']
As the description of your question is a little unclear and I'm confused about the meaning of I am already json parsing the file contents from the blob and this IS giving me the tokens, why is "tokens" involved in it ? And in the original question it seems you want to do it by jsonpath but in the latest description you said without jsonpath ? So if I misunderstand your question, please let me know. Thanks.
Not sure if I understand your question. But I believe you can use Pars Json action after the http trigger.
With this you will get a control over the incoming JSON message and you can choose the 'URL' value as a dynamic content in the subsequent actions.
Let me know if my understanding about your question is wrong.

Azure Resource Manager template chained functions

I am trying to remove / from the URL using azure function before assigning to output variable value
"webappStorageUri":{
"type": "string",
"value": "[take(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web, length(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web)-1]"
}
Returned value from length function should be the value for take function. This is not working. I get following error on deployment. I don't get anything out of this error message. Does Azure support chained function execution? Is this is right approach to remove / from the URL?
Error message
[error]Deployment template language expression evaluation failed: 'Unable to parse language expression 'take(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web, length(reference(resourceId('Microsoft.Storage/storageAccounts', variables('webappStorageName'))).primaryEndpoints.web)-1': expected token 'RightParenthesis' and actual 'Integer'.'. Please see https://aka.ms/arm-template-expressions for usage details.
I'm not sure what you are trying to achieve, but your function has issues with brackets, and you cannot really substract by appending -1 in a random place.
"[take(reference(variables('webappStorageName')).primaryEndpoints.web,
sub(length(reference(variables('webappStorageName')).primaryEndpoints.web), 1))]"
line breaks for readability only

Is there any possibility for adding thousand separator inside an Azure Logic App Expression?

Is there any possibility for adding thousand separator inside an Azure Logic App Expression?
I'm creating an Azure Logic App which sends an JSON to an REST Service. The JSON is build inside the Logic App with a Compose. The Data for the JSON comes from different REST Services.
The Services deliver me numbers like "13251", "11231543.3" etc.
I need to transform and send the numbers with thousand separator like "13.251", "11,231,543.3" etc.
My code looks like:
{
"Item": {
"nr": "#{body('current')?['nr']}",
"amount": "#{body('current')?['amount']}",
}
}
So I basically need something like: .ToString("#,##0.00")
"13251" => "13.251"
"11231543.3" => "11,231,543.3"
Thanks for your help!
You cannot send numbers with thousand separators in Json, since it will invalidate the Json.
Consider this Json:
{
"age": 123,456.0
}
This will be seen as:
{
"age": 123,
456.0
}
Which is invalid Json.
If you wish to format it as a string: there doesn't seem to be a conversion available to format numbers. There are several format-enabled conversions for DateTime.
More info: Reference guide to using functions in expressions for Azure Logic Apps and Microsoft Flow
You might want to try the Execute JavaScript code action for this. Sample:
enter image description here
Hope this Helps!
It can be achieved in logic app, but it's complicated. We can use "Math functions" in logic app(div and mod) and we also need to use "String functions", "if condition", "until" and initialize some variables. I achieved it by the actions and methods I mentioned above but it's too complicated. I think it is easy for us to do it by add additional code in azure function.

How do you iterate within an Azure Logic App Response component

I have an Azure MS SQL Server component that is returning multiple rows and feeding into a Response component.
The Body of the Response component looks like this:
{
"MyID":"#{body('Get_rows')['value'][1]['Id']}"
}
I can make the number in the bracket 0 and get the first result. I can make it 1 and get the second result. But what I am trying to find is the syntax to loop through all the results that are passed so that it would effectively provide the following (assuming there were 2 results total:
{
"MyID":"#{body('Get_rows')['value'][0]['Id']}"
}
{
"MyID":"#{body('Get_rows')['value'][1]['Id']}"
}
Thanks in advance for advice on where to find the correct syntax or for examples of correct syntax.
It took me a while but figured out that I needed to do two things:
I had to run a for each after the Get Rows and within that I created a Data Operations - Compose component. Within that I was able to create a single JSON object with all the parameters.
From there I used #outputs command as shown below in the Body of the Response and it inserted the array brackets and the commas to delimit the Compose entries automagically.
Here is what the code in the Body of the Response looks like:
#outputs('Compose')
Note that 'Compose' is the default name given to the first Compose component you place in the application.

Azure Resource Manager - Convert value to 'lower'

I was recently using ARM templates to deploy multiple resources into Azure. While deploying Storage accounts, I ran into an issue which was due to some constraints put up by Azure like
Name of Storage Account should not contain upper case letters
Its max length should be 24.
I want this name from the user and can handle the 2nd issue using the "maxLength" property on 'parameters'. But for lower case, there is no such property in 'parameters' also I'm unable to find any function which will convert the user entered value to lower case.
What I expect:
Method to convert the user entered value in lower case.
Any other method to suit my use case.
Thanks in advance.
You should look at the string function reference of the ARM templates.
you need to create a variable (or just add those functions to the name input, like so:
"name": "[toLower(parameters('Name'))]"
or add a substring method, something like this:
"variables": {
"storageAccountName": "[tolower(concat('sawithsse', substring(parameters('storageAccountType'), 0, 2), uniqueString(subscription().id, resourceGroup().id)))]"
},

Resources