Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

If Variable = something, set another variable as this

(0) ShareShare
ReportReport
Posted on by

Hi,

Can anyone please help with this:

In my flow, i get the body text of an email from the bottom line and set  VariableA. This VariableA could be either 1,2,3 or 4

I then want to set another variable called VariableB with a corresponding entry such as 1= dog, 2=cat, 3=rabbit, 4=parrot

 

I guess i need a Set Variable, but can anyone help with the  expression? I assume if statement but not sure

 

thanks

  • v-yetonggu-msft Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    Hi @Sharpharp ,

    I did another test for your reference.

    In my scenario:

    vyetonggumsft_2-1715928849832.png

    My Flow Parameters Configuration:

    vyetonggumsft_3-1715929008207.png

    trim(split(split(outputs('Get_message_details')?['body/body/plainTextContent'],'Choice ID:')[1],decodeUriComponent('%0A'))[0])
    
    if(equals(outputs('Compose'),'1'),'dog',
    if(equals(outputs('Compose'),'2'),'cat',
    if(equals(outputs('Compose'),'3'),'rabbit',
    'parrot')))

    Teams Channel Message:

    vyetonggumsft_4-1715929128915.png

    If you still have trouble extracting your Choice ID, can you please post a screenshot of your Teams message?

    I want to know the text structure inside so that I can better help you solve the problem.

    Best Regards,

    Sunshine Gu

     

  • Sharpharp Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    Sharpharp_0-1715852788738.png

     

  • v-yetonggu-msft Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    Hi @Sharpharp ,

    Could you please show me a screenshot of your flow?

     

    Best Regards,

    Sunshine Gu

     

  • Sharpharp Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    It helped, but didn't quite solve the issue. the html to text and trim commands were giving errors my side.

    I tackled it dfifferently using - trim(substring(outputs('Get_message_details')?['body/body/plainTextContent'] inside a for each message loop. The if statement was a big help, so thanks

     

  • v-yetonggu-msft Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    Hi @Sharpharp ,

    If I solve your problem, please mark my response as a solution so you and I can help more people who are experiencing this challenge in the future.

     

    Best Regards,

    Sunshine Gu

     

  • Sharpharp Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    thank you

  • v-yetonggu-msft Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    Hi @Sharpharp ,

    Please check this test:

    My Email:

    vyetonggumsft_3-1715567249412.png

    My Flow Overall Preview:

    vyetonggumsft_0-1715566990639.png

    My Flow Configuration Parameters:

    vyetonggumsft_1-1715567130600.png

    trim(split(split(outputs('Html_to_text')?['body'],'Choice ID:')[1],decodeUriComponent('%0A'))[0])
    
    if(equals(variables('A'),'1'),'dog',
    if(equals(variables('A'),'2'),'cat',
    if(equals(variables('A'),'3'),'rabbit',
    'parrot')))

    Best Regards,

    Sunshine Gu

  • Sharpharp Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    thanks for the quick reply. It seems my initial flow isn't working. 

    I want to get Variable A from the body of the email: I added the last line in the email which starts Choice ID: -then followed by 1,2,3 or 4

    Could you please help on how i get that 1,2,3 or 4 from the body of the email into Variable A.

    Can we read that last line in the email to grab what the CHOIC ID number is and chuck it into Variable A?

    Your if statement is perfect, happy with that bit so thanks.

  • Verified answer
    v-yetonggu-msft Profile Picture
    on at
    Re: If Variable = something, set another variable as this

    Hi @Sharpharp ,

    Please check this test:

    vyetonggumsft_1-1715332619089.png

    vyetonggumsft_3-1715332956769.png

    if(equals(variables('A'),'1'),'dog',
    if(equals(variables('A'),'2'),'cat',
    if(equals(variables('A'),'3'),'rabbit',
    'parrot')))

     Best Regards,

    Sunshine Gu

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492