cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Playman2006
Frequent Visitor

Use variable declared in Switch control

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? 

3 ACCEPTED SOLUTIONS

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

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. 

View solution in original post

6 REPLIES 6
Pstork1
Dual Super User III
Dual Super User III

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

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. 

Pstork1
Dual Super User III
Dual Super User III

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

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. 

Pstork1
Dual Super User III
Dual Super User III

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

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. 

View solution in original post

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Users online (64,257)