1
votes

I'am using an Azure Logic app to get Blob contents from my Azure container. The Blobs are getting stored monthly in my container in the format :- Eg. mycontainer/invoice/20200101/invoice1.csv, mycontainer/invoice/20200201/invoice2.csv, so on & so forth. In other words, every month's invoice is getting stored in my container dynamically with a folder denoting the month and day as in the example. (2020-01-01, yyyyMMdd format)

So far, I'am able to pick up the latest folder created in my container. That is October in this case, since we're in Oct. But I wish to pick up the latest file present in that folder.

My current workflow is as follows:-

Current Workflow

Any advice regarding this ? Thanks!

2
There is only one file in each folder ? Like mycontainer/invoice/20200101/invoice1.csv, mycontainer/invoice/20200201/invoice2.csv ? Or there are multiple files in each folder, like mycontainer/invoice/20200101/invoice1.csv, mycontainer/invoice/20200101/invoice2.csv, mycontainer/invoice/20200101/invoice3.csv ?Hury Shen
Exactly, only one file. But there's a unique name attached to the file name. Something like this -> mycontainer/invoice/20200101/BillingInvoice_c96d6c-497f-bb58-624237288cec.csv, mycontainer/invoice/20200201/BillingInvoice_d5lhk6-cd6c-49769-bb58-92002288cec.csv, like soSD4
Ok, I will test it in my side and then provide a solution below. But I want to know if the folder name 20200101 or 20200101-20200131Hury Shen
Yes @Hury, the folder name will be 20200101-20200131, 20200201-20200228,........ 20201001-20201031, 20201101-20201130, etc. This will be the format for the folder name. Every month, first date to last date, (yyyyMMdd format)SD4

2 Answers

2
votes

I provide entire logic app for your reference, most of actions are same as yours:

1. The overview of the logic app enter image description here

2. The first three actions enter image description here

3. Fourth and fifth action enter image description here

4. Details of "For each" loop enter image description here

The expression in "Set variable" is int(substring(items('For_each')?['Name'], 0, 8)) and the expression in "Set variable 3" is replace(items('For_each')?['Name'], '/', '')

5. The last two actions enter image description here

The last expression in "Get blob content" action is body('List_blobs_2')?['value'][0]?['Name']

====================================Update=================================

1. Delete the last action "Get blob content" of your logic app.

2. Then we start after the action "List blobs 2". Add two "Initialize variable". enter image description here

3. Add another "For each" loop. Please note: choose value from "List blobs 2" into "For each 2" but not choose value from "List blobs" into "For each 2". enter image description here

4. The details in the "For each 2" loop. enter image description here

The expressions of both fx ticks(...) are ticks(items('For_each_2')?['LastModified'])

And in "Set variable 5", also choose the Name from "List blobs 2" but not from "List blobs".

5. Then add "Get blob content" action like below screenshot. enter image description here

6. By the way: Please do this setting for all of the "For each" loop action in your logic app before you run the logic app. Otherwise, the result may be incorrect.

Click ... button of the "For each" action and click "Settings", enable Concurrency Control and set Degree of Parallelism as 1. enter image description here

0
votes

You can run an Event Grid trigger from your BLOB to Logic App. As soon as a new file is saved in the BLOB it can publish an event to Event Grid where your Logic App can subscribe to that event and then you can run your workflow. Rather than doing a loop this way you can trigger a logic app workflow every time a file is saved.

Learn more about Event Grid from here.