Search code examples
azure-logic-appsazure-logic-app-standard

How to use switch functions to check if the file name conatins ABC


I have created a logic app where I need to check if my file name contains "ABC" then i need to copy file and paste it in ABC folder Azure else need to check if my file name contains "ZYX" then paste it in ZYX folder in Azure.

In switch function its giving me an error.

"The execution of template action 'Switch' failed: The result of the evaluation of 'scope' action expression '@body('Get_file_content')' is not valid. It is of type 'Object' but is expected to be a value of type 'String, Integer'." [Image1]

or if I am trying to use 2 conditions in parallel branch its giving me the below error.

![Image2]

I also tried conditions, if the file name contains "ABC" then copy paste in ABC folder if false then i tried using another conditions inside the false command.

Also, follow up question would be if I have multiple file name with ABC then can I merge and place it in one file and paste that in ABC folder in Azure Blob

Image using switch function:

enter image description here

Image Conditions using parallel branch:

![Image Conditions using parallel branch] enter image description here

Attaching the latest screenshot with your suggestion. enter image description here

i just tried using one and its giving me the error. enter image description here


Solution

  • Reason for the error : You cannot passfile content as a condition check in the switch Connector.

    Solution: In order to get the desired output as described above you need to pass the file name as a condition check in switch control. As we receive the File Name from the SharePoint connector as base64 format we need to decode it to string using **base64ToString(FileName)** to compare the folder names present in the containers/blob.

    Here is the code view of the logic app based on the above-discussed requirement. enter image description here

    Also, follow up question would be if I have multiple file name with ABC then can I merge and place it in one file and paste that in ABC folder in Azure Blob

    Using the above flow, merging of files is not possible since each file is saved in different extensions but override of the file takes place in the blob if you are uploading or updating the same file.

    For more information about merging of files using Logic app you can refer this BLOG.

    UPDATED ANSWER

    Before Comparing the string/ Filename you can use 'Compose' before the 'Condition' Connector and convert the string into lower case.

    toLower(base64ToString(triggerOutputs()['headers']['x-ms-file-name-encoded']))
    

    enter image description here