Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

Using IF expression based on Choice selection - email body

(0) ShareShare
ReportReport
Posted on by 209

Hello,

 

I am creating a New Employee Hire form/flow and there's a column called "Department" (Choice). If the user selects "Accounting", I'd like to display specific text within the email body that is being triggered. If anything else is selected, I'd like to NOT show any special text. How can I accomplish this? I have tried several variations of the expression but am told it's incorrect. Am I close? -

 

if(equals('Department.Selected.Value',Accounting),'Grant edit permissions to vHUB's Accounting libraries','')

  • Morghan Profile Picture
    209 on at
    Re: Using IF expression based on Choice selection - email body

    Hi @Anonymous, @v-yuazh-msft and @ScottShearer -

     

    Another question in relation to this same flow I am building.... It relates to the same email body. I have another column in this "New Hire" process called "Using existing PC/laptop?" - In my custom form, I have it set to where if that is TRUE, the form will then display a text box next to the toggle on/off control where you can enter the name of the previous user of that PC/laptop. My goal is to, if "Using existing PC/laptop?" is TRUE, display the name that was entered into that text box; so the line in the email would read something like "Using PC/laptop that belonged to: <name>". The text box in the form is called "PreviousEmployeePC" -- I tried using the following expression (which returns valid, but does not print anything when testing): 

     

    if(equals(body('get_item')?['Using existing PC/Laptop?']?['Value'],true),'Will use existing PC from PreviousEmployeePC.Value','')

     

    Am I close??

  • Morghan Profile Picture
    209 on at
    Re: Using IF expression based on Choice selection - email body

    Even when commenting out, I get Invalid Expression. I ended up just removing it all together to read: 

     

    if(equals(body('get_item')?['Department']?['Value'],'Accounting'),'Grant edit permissions to vHUBs Accounting libraries','') 

    and verified it works as expected. thank you all.

  • Community Power Platform Member Profile Picture
    on at
    Re: Using IF expression based on Choice selection - email body

    Hi @Morghan,

     

    It looks like the ' is the problem from this part:

     

    vHUB's

     

    You can escape this. Try the following as an expression:

     

    if(equals(body('get_item')?['Department']?['Value'],'Accounting'),'Grant edit permissions to vHUB\'s Accounting libraries','')
  • Morghan Profile Picture
    209 on at
    Re: Using IF expression based on Choice selection - email body

    OK, @ScottShearer - I am making progress.. I was able to get the true false columns figured out (thank you). I am now just stuck on why the following does not work:

     

    if(equals(body('get_item')?['Department']?['Value'],'Accounting'),'Grant edit permissions to vHUB's Accounting libraries','')
     
    I am receiving "The expression is invalid" error:
     
    2019-01-14_14-57-39.jpg
  • Morghan Profile Picture
    209 on at
    Re: Using IF expression based on Choice selection - email body

    I apoligize. I provided the incorrect error. I WAS getting "Inavlid Expression" but fixed that. The error I am getting at this time when SAVING my flow after adding the expression is: "The template validation failed: 'The action(s) 'get_item' referenced by 'inputs' in action 'Send_an_email_to_Vestar_IT_and_itSynergy' are not defined in the template.'."

     

    @v-yuazh-msft, @ScottShearer

     

    Thanks again for your assistance.

  • Morghan Profile Picture
    209 on at
    Re: Using IF expression based on Choice selection - email body

    Hi @ScottShearer,

     

    Thank you for reply. I apologize for the delayed response. Taking your example, here is what my true false expression looks like:

     

    if(equals(body('get_item')?['MRI'],true),'MRI','')

     

    However, I am still receiving "Invalid Expression" error in Flow. If it helps, here is a screenshot of what I am trying to do. I am trying to print the text "MRI" in this email body if the value of the "MRI" column is TRUE,  else do not print anything:

     

    flow-screenshot-1.jpgI am confused on how the 'get_item' works (in regards to both of my questions). I tried playing with it a little bit but am lost. Am I supposed to just be adding a Get Item action before the email action?

  • v-yuazh-msft Profile Picture
    on at
    Re: Using IF expression based on Choice selection - email body

    Hi @Morghan,

     

    Could you please share a screenshot of the configuration of your flow?

    What is the trigger in your flow?

     

    Best regrads,

    Alice

  • Verified answer
    ScottShearer Profile Picture
    25,212 Most Valuable Professional on at
    Re: Using IF expression based on Choice selection - email body

    @Morghan:

     

    You can use an If expression to test for the value of a true false column:

     

    if(equals(body('get_item')?['TrueFalseColumn'],true),'I am true','I am not true')

     

    Please note that there are no quotes around true - it is not a string.

     

    If this answers your question, please mark your post as solved.

     

    Scott

  • ScottShearer Profile Picture
    25,212 Most Valuable Professional on at
    Re: Using IF expression based on Choice selection - email body

    @Morghan:

     

    I ran a test using a For a Selected Item trigger and a Get Item action and the following worked for me:

    if(equals(body('get_item')?['Department']?['Value'],'Accounting'),'Grant edit permissions to vHUB's Accounting libraries','')

     

    In the example you posted, you just referenced the column name and Flow doesn't understand that.  Select the value that you want to reference in your expression from Dynamic properties - switch back to Dynamic properties while you are in your expression, select the value you want and then switch back to the expression and continue.  That way, Flow will add what it needs in order to grab that value from the trigger or action that is supplying the value.

     

    This may sound a little confusing - it you need more help, please post here.

     

    If this answers your question, please mark your post as Solved.

     

    Scott

     

     

  • Morghan Profile Picture
    209 on at
    Re: Using IF expression based on Choice selection - email body

    Another related question would be how to display specific text based on true/false values for certain columns?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow