web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Use variable declared ...
Power Automate
Unanswered

Use variable declared in Switch control

(0) ShareShare
ReportReport
Posted on by

Hello, 

 

I am trying to create a flow that takes in variable data from a Powerapp (this is irrelevant) and pushes that data to a Graph API. I am currently using a Switch control to evaluate the "UserType" variable I receive from my App. Depending on the type it populates an initialized variable with the proper Json object. 

Right now i need to take that populated variable, no matter the type and place into the Graph API call, but Flow is not giving me the "dynamic" option to place it into the field. which leads me to believe I can't access it unless i do this call separately for every switch case... I don't want to do this. Is there a way to Join the switch branches back together so i can access my data no matter what the switch does? 

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,678 Most Valuable Professional on at
    Re: Use variable declared in Switch control

    If you are using a flow initialized variable then it should be scoped for the entire flow.  It may not be showing in the dynamic content dialog because that dialog is filtered based on the data type expected in the action.  Since you mentioned its a JSON object you may have to use a compose to get a specific property out of the JSON for use as dynamic content.

  • Community Power Platform Member Profile Picture
    on at
    Re: Use variable declared in Switch control

    Thanks for the prompt reply, So your saying that if i want to use the data stored in the switch i will have to do a custom call? such as: variables('Variable name')..... does this look right? Also, i actually don't need to pull the individual data out of it, the GraphAPI just needs it in Object format. 

  • Verified answer
    Pstork1 Profile Picture
    68,678 Most Valuable Professional on at
    Re: Use variable declared in Switch control

    No, I'm not saying you need to do a custom call, although that might work also.

     

    To use a variable in a flow the variable needs to be initialized somewhere in the mainline of the flow.  You can't initialize a variable inside a condition or a loop or a scope statement.  After a variable is initialized, at which point you select the data type, you can set the value of the variable anywhere inside the flow.  You can also use it anywhere inside the flow. But the Dynamic content dialog filters available values based on the data type expected in the field you are filling in.  So if you create an object type variable you won't see it if the action you are trying to fill in requires a String.

     

    So where are you initializing the variable, where are you setting its value, what data type is it, and where are you trying to use it and don't see it?  Screenshots and an explanation of what you are trying to accomplish would be very helpful.

  • Community Power Platform Member Profile Picture
    on at
    Re: Use variable declared in Switch control

    Yes, i am initializing the Variable outside of the Switch condition and then setting the variable depending on the condition met. All addressing the initialized variable. The Variable type is an object that i am hoping to use a JSON object. This will be a simple Compose operation with a multiple value schema... not a multiple items. Here are some screen shots to help clarify. 

     

     

    Playman2006_0-1597699492112.png

    This is my initialization. ... 

    Playman2006_1-1597699551638.png

    This is the switch condition that i am using. You can see me trying to compose the object on the top left, then ( i may scrap this part) parse it into a proper JSON. then underneath that I set the Variable License. 

     

    Playman2006_2-1597699675157.png

    Here is what i am doing below. I am calling the Licenses variable using the variables('Licenses') like we discussed, but haven't been able to test that theory because it fails on the "Compose" json piece above. Could you double check my schema to make sure i am composing it properly. After that I can truly tell if my theory is correct. 

     

    Sorry for all the extra details, as you know flows don't let you skip around very easily. 

  • Verified answer
    Pstork1 Profile Picture
    68,678 Most Valuable Professional on at
    Re: Use variable declared in Switch control

    Based on the field you are filling in it looks like its expecting a JSON array, not a JSON object.  Otherwise everything looks correct.  The only other issue is that I'm not sure an object in Power Automate will automatically be cast as a JSON object.  That may be the problem you are having setting the JSON object above.

  • Verified answer
    Community Power Platform Member Profile Picture
    on at
    Re: Use variable declared in Switch control

    Well i found the solution in this was like what you were saying. It was that the variable context was not available for PA to find. So i had to declare the "expression" variables('var Name') and find them that way. Which works. As for my next question, irrelevant to the post, Assign license Graph API is not allowed within Create User post. (which should be altered, why would that not be needed that is VERY common when creating a user) So i have to create the user then do a AssignLicense post as well. 

     

    Thank you for your support your answer did help clarify things. 

  • Formatron Profile Picture
    65 on at
    Re: Use variable declared in Switch control

    Thank you, this was helpful - I've just added a variable into my flow using your advice.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard