cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Setting variables with expressions, documentation and testing suggestions

I have some programming experience with JS on linux-based systems. I cannot find a good way to work with flow and expressions. What I usually do to understand new languages/syntax is to make a test environment to confirm my understanding as I go along reading the documentation. Creating a flow that notifies my mobile app to see whether my expression is correct is not a viable solution. I'd like to use a simple compiler/tool similar to jsfiddle.net but i cannot even figure out what syntax to use, I guess it is because it is obvious to most people working with flow(utilizing expressions) as they come from developing in "Microsoft languages".

 

Right now I am trying to set a variable to find the name of the parent directory for a file(onedrive for business-path), reason for this is that the workflow I'm trying to automate has some conventions like folder-naming and such. I create an array ('fpArr') by initializing a variable as array and splitting the path by '/'. So far so good, but getting the second last item from that array is somewhat confusing. In other languages I could use something like fpArr[-1:] but this does obviously not work with flow-expressions.

 

To set a variable with the parent folder from a file-path(array), I've been trying carzy things like:

 

variables('fpArr')[int(sub(variables('fpArr').length, 2))]

I'm obviously not even in the ballpark on this. The example is just to illustrate how confused I am. Please help me find a good way to test expressions and documentation that is suitable for my background. 🙂 

 

Edit: found some information here: azure logic-apps

It seems that references to complex documentation is almost invisible in the flow-documentation. 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Setting variables with expressions, documentation and testing suggestions

Hi @hjaf,

 

Could you please share a screenshot of your flow's configuration?

 

In order to get the name of the parent directory for a file (OneDrive for Business), I have created folders within my OneDrive for Business as below:32.JPG

I create a file within Parent Directory1 folder and want to get the name of Parent Directory1 using Microsoft Flow, I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use "When a file is created (properties only)" trigger of OneDrive for Business connector.
  • Add a Variables-> "Initialize variable" action, Name set to PathArray, Type set to Array and Value set to following formula:
split(triggerBody()?['Path'],'/')
  • Add a Variables-> "Initialize variable 2" action, Name set to Parent Folder, Type set to String and Value set to empty.
  • Add a "Compose" action, Inputs set to following formula:
length(variables('PathArray'))
  • Add a "Set variable" action, Name choose Parent Folder, Value set to following formula:
variables('PathArray')[sub(outputs('Compose'),2)]

Image reference:33.JPG

The flow works successfully as below:34.JPG

 

More details about the WDL expression in Microsoft Flow, please check the following article:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language 

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Highlighted
Community Support
Community Support

Re: Setting variables with expressions, documentation and testing suggestions

Hi @hjaf,

 

Could you please share a screenshot of your flow's configuration?

 

In order to get the name of the parent directory for a file (OneDrive for Business), I have created folders within my OneDrive for Business as below:32.JPG

I create a file within Parent Directory1 folder and want to get the name of Parent Directory1 using Microsoft Flow, I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use "When a file is created (properties only)" trigger of OneDrive for Business connector.
  • Add a Variables-> "Initialize variable" action, Name set to PathArray, Type set to Array and Value set to following formula:
split(triggerBody()?['Path'],'/')
  • Add a Variables-> "Initialize variable 2" action, Name set to Parent Folder, Type set to String and Value set to empty.
  • Add a "Compose" action, Inputs set to following formula:
length(variables('PathArray'))
  • Add a "Set variable" action, Name choose Parent Folder, Value set to following formula:
variables('PathArray')[sub(outputs('Compose'),2)]

Image reference:33.JPG

The flow works successfully as below:34.JPG

 

More details about the WDL expression in Microsoft Flow, please check the following article:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language 

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (8,488)