question

TWest-1253 avatar image
0 Votes"
TWest-1253 asked MayankBargali-MSFT edited

How to extract part of a file name using logic apps

Hi,

I have a Logic Apps process built which processes files uploaded onto our SFTP server.

The file naming convention is <DIGITS>_<FILENAME>. I would like to somehow extract the digits from the filename to pass as a parameter into a stored procedure.

What would be the best method of extracting the digits please? Essentially I need all numbers at the start of the file name prior to the first "_" (underscore).

Any help would be very much appreciated.

Thanks!

azure-logic-apps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT edited

@TWest-1253 Within the logic app you can use inline code and write javascript code to get the digit part of your filename. For testing purposes, I have defined the filename to the var text. But you can use the workflowContext object to get the fileName as mentioned in the inline code document.

 var text = "1244_test";
 var digit= text.split('_')[0];
 return digit;

Updated:
You can also use split if you don't have complex logic.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the reply @MayankBargali-MSFT . Unfortunately we don't have an Azure integration account to use the inline code function. Is there any other way around this please?

Thanks

0 Votes 0 ·

@TWest-1253 In that case you can also use split. For testing, I have hardcoded the value but you can use Dynamic Content available in your logicapp.

98985-image.png


0 Votes 0 ·
image.png (19.5 KiB)

Thanks a lot @MayankBargali-MSFT. I was wondering, if the file name happens to have multiple underscores "_", what would be the best way to ensure that only the digits to the left of the first underscore are selected?

Thanks

0 Votes 0 ·
Show more comments

One other question please....is it possible to also capture all text to the right of the first underscore (even if there are additional underscores)? I changed the [0] to a [1] but this only partially captured the file name (due to there being a further underscore in the filename)

Thanks,

0 Votes 0 ·
Show more comments