1

I need to send the blobs uploaded to my Azure storage container as an attachments. Number of files getting uploaded to container will change so I need to use dynamic method for attachment. I have verified this question related to it

I am using below logic:

enter image description here

Append to variable values

{

"Name": items('For_each')?['DisplayName']
"ContentBytes":body('Get_blob_content')

} When I am trying to save the logic, getting below error:

Save logic app failed
Failed to save logic app testing. The template validation failed: 'The action(s) 'Get_blob_content' referenced by 'inputs' in action 'Append_to_array_variable' are not defined in the template.'.

How can I solve this ?

acr
  • 1,674
  • 11
  • 45
  • 77
  • By following the above shared steps, we have created a workflow & tested in Our local environment which is working fine Here is the [screen shot](https://i.imgur.com/JzTnbV5.png) for your reference: We have used the same logic in the `appendtoarrayvariable` & able to save the logic app as shown in this [GIF](https://imgur.com/BJo8pJe) . – VenkateshDodda Dec 17 '21 at 04:15
  • Instead, of saving the entire workflow at once would suggest you to save the logic app at each stage or before the `appendtoarray` variable stage & post then append the values to attachment variable with previous stage outputs. – VenkateshDodda Dec 17 '21 at 04:15
  • @VenkateshDodda-MT: Thanks. It giving error https://imgur.com/a/lQ3SSd9 in for loop. In Get Blob content inside loop, how me mention the blob ? DO we need to take reference from List Blob or from the first trigger (When lob is uploaded). Sorry, I am new to this and getting confused with it – acr Dec 17 '21 at 06:17
  • 1
    please refer the blob path , from the list blob operations only in get blob content action as shown in this [image](https://i.imgur.com/3SQiBPR.png) – VenkateshDodda Dec 17 '21 at 06:23
  • @VenkateshDodda-MT: Thanks, made changes. I am getting error at send email action now. This is the error - https://imgur.com/a/lQ3SSd9 – acr Dec 17 '21 at 06:45
  • 1
    Please use the below expression for the content variable "Content": `base64(body('Get_blob_content_(V2)'))` in the Append to array variable block as shown in below image `https://i.stack.imgur.com/vI7kP.png – VenkateshDodda Dec 17 '21 at 06:49
  • @VenkateshDodda-MT: Thanks, it worked now. But I am getting more than one email with multiple attachment. Send email action is out side for loop. Any suggestions - https://imgur.com/a/ubVjCEE – acr Dec 17 '21 at 06:57
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240224/discussion-between-venkateshdodda-mt-and-acr). – VenkateshDodda Dec 17 '21 at 07:07

1 Answers1

1

Based on the error message shared above, Instead of saving the entire workflow at once would suggest you to save the logic app at each stage or before the appendtoarray variable stage & post then append the values to attachment variable with previous stage outputs.

Based on the above requirement, we have created the below logic app in our local environment &tested it as well which is working fine.

In our workflow, We have Used For Each to loop the blobs from List Blobs action. Within For Each you can use Get blob content to get blob content, and then use Append to array variable to append attachments.

The expressions Name and ContentBytes are as follows:

 "ContentBytes": "@base64(body('Get_blob_content_(V2)'))",
 "Name": "@items('For_each')?['DisplayName']"

enter image description here

Here is the code view of the Logic app that we have created :

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "attachments",
                            "value": {
                                "ContentBytes": "@base64(body('Get_blob_content_(V2)'))",
                                "Name": "@items('For_each')?['DisplayName']"
                            }
                        },
                        "runAfter": {
                            "Get_blob_content_(V2)": [
                                "Succeeded"
                            ]
                        },
                        "type": "AppendToArrayVariable"
                    },
                    "Get_blob_content_(V2)": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent(items('For_each')?['Path']))}/content",
                            "queries": {
                                "inferContentType": true
                            }
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "foreach": "@body('Lists_blobs_(V2)')?['value']",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "attachments",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Lists_blobs_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Lists_blobs_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJmcmVwb3J0cw=='))}",
                    "queries": {
                        "nextPageMarker": "",
                        "useFlatListing": false
                    }
                },
                "metadata": {
                    "JTJmcmVwb3J0cw==": "/reports"
                },
                "runAfter": {},
                "type": "ApiConnection"
            },
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Attachments": "@variables('attachments')",
                        "Body": "<p>tested logic app flow successfully</p>",
                        "Subject": "blob test",
                        "To": "<username>@microsoft.com"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_blob_is_added_or_modified_(properties_only)_(V2)": {
                "evaluatedRecurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/triggers/batch/onupdatedfile",
                    "queries": {
                        "checkBothCreatedAndModifiedDateTime": false,
                        "folderId": "JTJmcmVwb3J0cw==",
                        "maxFileCount": 10
                    }
                },
                "metadata": {
                    "JTJmcmVwb3J0cw==": "/reports"
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "/subscriptions/<sub-ID>/resourceGroups/<resourceGroup>/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "id": "/subscriptions/<sub-id>/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
                },
                "office365": {
                    "connectionId": "/subscriptions/<sub-id>/resourceGroups/<resroucegroup>/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/<sub-id>/providers/Microsoft.Web/locations/eastus/managedApis/office365"
                }
            }
        }
    }
}

Here is the sample Output for reference:

enter image description here

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12