cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ishraqiyun77
Resolver I
Resolver I

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

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?

View solution in original post

3 REPLIES 3

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?

v-bacao-msft
Community Support
Community Support

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.

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

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (1,241)