Output of Stored Proc in Logic apps not becoming Dynamic content - azure-logic-apps

I've made a Stored Proc and I've initialized it in a variable and am trying to make the output of the Stored Proc Dynamic content in Logic Apps, however. Once I put the variable in the Parse JSON step, it will not become Dynamic. Any advice on how to make my Stored Proc output Dynamic content?
My output varies on the number of entries I'm able to retrieve and I think that's my issue. I've set my Parse JSON scheme to look for 6 entries and sometimes I will get 8-10, which I believe is my problem How can I make it so that no matter how many entries come through from my Stored Proc, I can capture those values in dynamic content and use them?

I see that you are trying to check the SQL dynamic content rather than checking the Parse JSON Connector. Make sure you are checking in the dynamic content of Parse JSON.
Also, after reproducing from my end, I could able to get the expected results without using Parse Json too.
when you follow the above the process you can retrieve no matter how many entries are there in the table. Below is the complete flow that worked for me.
Below is the schema of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Execute_stored_procedure_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['sql']['connectionId']"
}
},
"method": "post",
"path": "/v2/datasets/#{encodeURIComponent(encodeURIComponent('default'))},#{encodeURIComponent(encodeURIComponent('default'))}/procedures/#{encodeURIComponent(encodeURIComponent('[dbo].[proc1]'))}"
},
"runAfter": {},
"type": "ApiConnection"
},
"Parse_JSON": {
"inputs": {
"content": "#body('Execute_stored_procedure_(V2)')",
"schema": {
"properties": {
"OutputParameters": {
"properties": {},
"type": "object"
},
"ResultSets": {
"properties": {
"Table1": {
"items": {
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
}
},
"required": [
"firstname",
"lastname"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"ReturnCode": {
"type": "integer"
}
},
"type": "object"
}
},
"runAfter": {
"Execute_stored_procedure_(V2)": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"sql": {
"connectionId": "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Web/connections/sql",
"connectionName": "sql",
"id": "/subscriptions/xxxx/providers/Microsoft.Web/locations/eastus/managedApis/sql"
}
}
}
}
}

Related

Logic app loop through all elements on the array and add it to the body/description

Actually I don't know if this will work. But I have long array with a lot of elements, I need to display all element in order on the body/description of Jira ticket without writing it manually (example: outputs('Compose')?[0] outputs('Compose')?[1] outputs('Compose')?[2] ). Is there anyway to do it using loop? or any other method?
Note: I don't want it to be as paragraph I need it the same as the array listed.
Example array:
[ 'first element', 'second element', 'third element', ]
printed/displayed format:
first element
second element
third element
I tried using loop but don't understand it.
please consider that I'm new to the Logic App or any other technologies with the same idea
There are ways which we can perform data operations such as:
Line by line
Spaces
Option 1: Line by line
Firstly, I have initialized a variable as below:
Then used Join (Data Operations) as below:
(here I just clicked Enter in Join with )
Output:
Code view:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "emo",
"type": "array",
"value": [
"rithwik",
"bojja",
"chotu"
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Join": {
"inputs": {
"from": "#variables('emo')",
"joinWith": "\n"
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Join"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
So now you can use the output of Join(body('Join')
Option 2: Spaces
If you keep space in Join you will get ouput as below:
Output:
Code view:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "emo",
"type": "array",
"value": [
"rithwik",
"bojja",
"chotu"
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Join": {
"inputs": {
"from": "#variables('emo')",
"joinWith": " "
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Join"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
I'm going to assume that what you end up putting together needs to be separated by a html line break (i.e. <br>) but if this not the case then you can make it whatever you want.
I've just tried to mimic what you provided with this basic flow ...
You can see the first step is a compose for your array and the second step is initialising a string variable using the join expression. This concatenates all strings within the array together separated by the HTML line break.
join(outputs('Compose'), '<br>')
Result

get emails for last x number of hours in logic app

I am using "get emails v3" action in "outlook.com" for logic apps. I want to search emails based on subject filters in todays date only. I want following search criteria where I want emails between two times.
((receivedDateTime:#{utcNow()})) BETWEEN (receivedDateTime:#{addToTime(utcNow(), 1, 'Day')})
Is there any way to do that?
After reproducing it was clear that this is because of the format of receivedDateTime is not as same as the format of utcNow(). To achieve your requirement, you need to compare the dates in same format using condition. Below is how I to achieve your requirement using condition action.
Left side Condition
formatDateTime(items('For_each_2')?['receivedDateTime'],'dd/MM/yyyy')
Right side Condition
formatDateTime(addDays(utcNow(), -1), 'dd/MM/yyyy')
Here is the complete flow of my logic app
RESULTS:
Below is the code view of my Logic App
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each_2": {
"actions": {
"Condition": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "Email",
"value": "#items('For_each_2')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"expression": {
"and": [
{
"greaterOrEquals": [
"#formatDateTime(items('For_each_2')?['receivedDateTime'],'dd/MM/yyyy')",
"#formatDateTime(addDays(utcNow(), -1), 'dd/MM/yyyy')"
]
},
{
"lessOrEquals": [
"#formatDateTime(items('For_each_2')?['receivedDateTime'],'dd/MM/yyyy')",
"#formatDateTime(utcNow(),'MM/dd/yyyy')"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"foreach": "#body('Get_emails_(V3)')?['value']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_emails_(V3)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "get",
"path": "/v3/Mail",
"queries": {
"fetchOnlyFlagged": false,
"fetchOnlyUnread": false,
"fetchOnlyWithAttachment": false,
"folderPath": "Inbox",
"importance": "Any",
"includeAttachments": false
}
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Email",
"type": "array"
}
]
},
"runAfter": {
"Get_emails_(V3)": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/<SUBID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<SUBID>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
}
}
}
}
}
If I've understood you correctly then this is the sort approach you need to take.
There's an additional parameter to that connector called Search Query.
In there, you can put an expression that looks like the following ...
received>#{formatDateTime(addDays(utcNow(), -1), 'MM/dd/yyyy')}
You're close, if you look at the doco though, the name of the field is different to what comes back in the response.
https://learn.microsoft.com/en-gb/graph/search-query-parameter
You may just need to play around with the formula to give you exactly what you want given the response is all in UTC. I think -1 day is the easiest but it may not be perfect for you.

Azure Logic apps - output array in email body

I have trouble using my array variable in my V2 email in Logic apps. I would like to output my array in the email body. For example if my array is ["1","2",3"]. Im want each value on its own row.
1
2
3
I have 2 issues, outputting my array in the email body(only strings showing in the dynamic menu) and making each value on a row.
After reproducing from my end, I could able to achieve your requirement by replacing "," with "< br>< br>" while sending the email using Send an email (V2) action. Below is the expression that worked for me.
replace(string(variables('SampleArray')),',','<br><br>')
Here is the flow of my Logic App
Result in my Inbox:
To reproduce the same, you can use below codeview in your logicapp
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"SampleArray": {
"inputs": {
"variables": [
{
"name": "SampleArray",
"type": "array",
"value": [
1,
2,
3
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>#{replace(string(variables('SampleArray')),',','<br><br>')}</p>",
"Importance": "Normal",
"Subject": "Sample",
"To": "<YOUR-EMAIL>"
},
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"operationOptions": "DisableAutomaticDecompression",
"runAfter": {
"SampleArray": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/<SUB-ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<SUB-ID>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
}
}
}
}
}

Queue Name is not binding to azure logic app after deployment

I am trying to deploy the Azure logic app to two environments ie. dev and prod.
I am using a single json file for the logic app and for the environments I have different parameter files. The Azure pipeline picks the parameter file as per the environment. All the parameters defined in the parameters files get bound during deployment, but I'm having issues with the queue name.
This is how I am defining parameters in the parameters files:
"parameters": {
"logicAppName": {
"value": "Test-App-dev"
},
"QueueName": { "value": "testdev" }
}
This is how it is used in path variable in logic app json file:
But after deployment, the queue name is not reflecting on the Azure portal. This is how it looks like in the Azure portal:
After reproducing from our end, we found that this is due to an invalid template. Here is how we could able to pull off the required value.
Created the below parameter
"parameters": {
........
,
"QueueName": {
"defaultValue": "testdev",
"type": "String"
}
}
Now you need to add the same in the template's parameter
"parameters": {
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "[parameters('connections_servicebus_1_externalid')]",
"connectionName": "servicebus-1",
"id": "***"
}
}
},
"QueueNamedev": {
"value": "[parameters('QueueName')]"
}
}
Declare the same in your definition's parameter
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"$QueueNamedev": {
"defaultValue": {},
"type": "String"
}
}
RESULT:
Finally, we could able to read its value as 'testdev'. You can check from parameters that the value of QueueNamedev is read as testdev.
Below is the template of my logic app
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflows_LogicApp12_name": {
"defaultValue": "LogicApp12",
"type": "String"
},
"connections_servicebus_1_externalid": {
"defaultValue": "/subscriptions/<YourSubscriptionID>/resourceGroups/<YourResourceGroup>/providers/Microsoft.Web/connections/servicebus-1",
"type": "String"
},
"QueueName": {
"defaultValue": "testdev",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('workflows_LogicApp12_name')]",
"location": "centralus",
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"QueueNamedev": {
"defaultValue": {},
"type": "String"
}
},
"triggers": {
"When_a_message_is_received_in_a_queue_(auto-complete)": {
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"evaluatedRecurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus_1']['connectionId']"
}
},
"method": "get",
"path": "/#{encodeURIComponent(encodeURIComponent(parameters('QueueNamedev')))}/messages/head",
"queries": {
"queueType": "Main"
}
}
}
},
"actions": {},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "[parameters('connections_servicebus_1_externalid')]",
"connectionName": "servicebus-1",
"id": "/subscriptions/<YourSubscriptionID>/providers/Microsoft.Web/locations/centralus/managedApis/servicebus"
}
}
},
"QueueNamedev": {
"value": "[parameters('QueueName')]"
}
}
}
}
]
}

Convert CSV file as array in logic apps

I want to read CSV file as array in logic apps. I didn't find any documents related to it. Any help on this would be appreciated. Thank you!
Based on your question here are few arounds that we can try below either way for 2 different outputs.
READ EACH OBJECT CSV FILE AS ARRAY OBJECT:
We can use split and add the output of the compose connector into Array by adding 'Initialise Variable' Connector and for converting each word into array variable we need to add for each connector inside another for each connector to iterate the items inside the CSV file then with a split variable inside the inner for each connector having split(item(),',') expression.
READ EACH ROW IN CSV FILE AS AN ARRAY:
We can use Plumsail's Parse CSV connector in order to convert each CSV row as an array considering headers in the CSV file.
Here are the screenshots for your reference
Expression in compose connector
split(body('Get_blob_content_(V2)'),'\n')
Expression in For each 2 connector
split(item(),',')
Note: Make sure you go to your code view and change the expression in your split from
split(body('Get_blob_content_(V2)'),'\\n') to split(body('Get_blob_content_(V2)'),'\n') as when we are writing the expression for this it first takes '\n' as string and adds another "" to the expression.
Here is the code view of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#split(body('Get_blob_content_(V2)'),'\n')",
"runAfter": {
"Get_blob_content_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_2": {
"inputs": "#variables('array1')",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "array1",
"value": "#items('For_each_2')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "#split(item(),',')",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "#outputs('Compose')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_blob_content_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['azureblob_1']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/#{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/#{encodeURIComponent(encodeURIComponent('JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2": "/container24/data-article.csv"
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "array1",
"type": "array",
"value": "#outputs('Compose')"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_CSV": {
"inputs": {
"body": {
"content": "#{base64(body('Get_blob_content_(V2)'))}",
"headers": "url,user_id,token_id,username,password"
},
"host": {
"connection": {
"name": "#parameters('$connections')['plumsail']['connectionId']"
}
},
"method": "post",
"path": "/flow/v1/Documents/jobs/ParseCsv"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob_1": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups<Your resourec group >/providers/Microsoft.Web/connections/azureblob-1",
"connectionName": "azureblob-1",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/azureblob"
},
"plumsail": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups/<Your resourec group >/providers/Microsoft.Web/connections/plumsail",
"connectionName": "plumsail",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/plumsail"
}
}
}
}
}
REFERENCES:
Convert CSV elements into a single Array using Azure Logic Apps - Stack Overflow

Resources