cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ishraqiyun77
Level: Powered On

Trying to use IF() on a field's value to determine what value to send to the other web API

I'm trying to use an expression in a Flow, neither of which I have a great extent of experience with.

I have a dropdown in Dynamics 365 that has three values to choose from. Based on what is selected should determine the value that is sent to the other web API. I just keep getting an "expression is invalid."

Here is what I've tried:

if(triggerBody()?['tst_projecttemplate']='Test1','123456','0')

And:

if(parameters('tst_projecttemplate')='Test1','123456','0')

Furthermore, I might need to nest them--that is if the act like Excel IF(). Like so:

if(triggerBody()?['tst_projecttemplate']='Test1','123456',triggerBody()?['tst_projecttemplate']='Test2','654321','0'))

Anyway, what is the correct format to get the value from a field, have conditional logic on it, and furthermore nest them to accomodate more than one option.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Trying to use IF() on a field's value to determine what value to send to the other web API

Hi @ishraqiyun77 you're not far off. The issue is with the way you're trying to validate the condition, it's not quite like development whereby you can use a Condition=Value pattern. You have to use an expression which validates as true or false.

 

Therefore your expression should look like this:

if(equals(triggerBody()?['tst_projecttemplate'],'Test1'),'123456','0')

The expression in bold will now validate as true or false, which is what the "if" expression wants within the first parameter.

 

Yes you can nest them, however keep in mind that in a one line expression editor it can become messy very quickly. Is there a reason you're going down this route rather than using conditions or switches in the graphical method?





Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!





3 REPLIES 3
Super User
Super User

Re: Trying to use IF() on a field's value to determine what value to send to the other web API

Hi @ishraqiyun77 you're not far off. The issue is with the way you're trying to validate the condition, it's not quite like development whereby you can use a Condition=Value pattern. You have to use an expression which validates as true or false.

 

Therefore your expression should look like this:

if(equals(triggerBody()?['tst_projecttemplate'],'Test1'),'123456','0')

The expression in bold will now validate as true or false, which is what the "if" expression wants within the first parameter.

 

Yes you can nest them, however keep in mind that in a one line expression editor it can become messy very quickly. Is there a reason you're going down this route rather than using conditions or switches in the graphical method?





Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!





Highlighted
Community Support Team
Community Support Team

Re: Trying to use IF() on a field's value to determine what value to send to the other web API

Hi @ishraqiyun77 ,

 

Basically, we need to replace the operator with a logical expression, the operator cannot be used directly in expression.

Please refer to the links below to learn to use expressions to compare multiple values.

Https://lazyadmin.nl/office-365/working-with-expression-in-microsoft-flow/

Https://faustocapellan.com/2018/06/14/express-yourself-logical-functions-in-microsoft-flow/

Also, please refer to the online doc for more details on the WDL function:

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

Hope it helps.

 

Best Regards,

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

Re: Trying to use IF() on a field's value to determine what value to send to the other web API

Hi @ishraqiyun77 if one of the posts in this thread have answered your question, can you please mark it as an answer?





Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!





Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

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

thirdImage

New Flow Community Board!

Check out the new Microsoft Flow Community Blog Topic Suggestion board!

fourthImage

Australia Summit

Travel to Melbourne and network with thousands of peers!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 78 members 4,366 guests
Please welcome our newest community members: