cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PhilStanley
Helper I
Helper I

Switch function not working, expecting string and not object

I am a newbie so please bear with me.

I have created a Power Automated flow from a Form to Dataverse. Most of the items I have mapped to the fields. There are a few which I need to collect that come under the same name. I am trying to use a 'Switch' function to extract the relevant 32 character long strings (as I cannot access the actual form questions) but I've tried "List of response notifications", "Current Item", "Body" but keep getting variations of the following:
"The execution of template action 'Switch' failed: The result of the evaluation of 'scope' action expression '@items('Apply_to_each')' is not valid. It is of type 'Object' but is expected to be a value of type 'String, Integer'."Switch.png

 


I cannot find anywhere on the web where it can tell me what I should be putting in the Switch function for this to work.

Apart from the above error detail I also get a message saying:
"This is a new issue. Try posting about it on our community page—somebody may have a fix. Post it now"
Hence I am posting this. Any help is appreciated as I have been stuck on this same problem for about 4 days.

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Community Champion
Community Champion

Hi @PhilStanley 

 

If only 1 has an answer and 14 are empty you can simply construct a concat expression as per my example above.  Concat will concatenate all of the answers from the 15 strings.  If only 1 is complete, you will end up with the 1 answer and no need to worry about complex switch statements.  Concating an empy string to and empty string gives you nothing and so it will only supply you with the single answer.

 

Go into the expression builder, type concat() and then back to dynamic and select each field you require with a comma between them all.

 

Unless I have completely misunderstood, this makes your life a lot easier and you save the result of the concat back to dataverse.

 

Damien

View solution in original post

8 REPLIES 8
DamoBird365
Community Champion
Community Champion

Hi @PhilStanley 

 

First thing you need to do is get the "Get Response" action out of your apply to each.  It should be after your trigger and it will only retrieve the answers for 1 submission of your form.  Each flow run will return the answers for that submission only.

 

Then try adding a compose action and then see if you can see the dynamic fields aka your answers to the questions.  

 

Potentially no need for your apply to each.  If I was you, strip it back trigger, get response and compose and then run it with a new form submission and then take a look at the history of the run.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


Hi @DamoBird365 

 

Thanks for that. I do get the answers but need to explain a bit more about this.

The form I have is using cascading dropdowns where one dropdown leads to others. Hence I will have a lot of empty answers.  The form has about 15 questions named "Site" which I want to find the site that is chosen and assign it to the field named "Site" in Dataverse.

I was hoping to use a 'switch' function to put in all the 15 ("Site") 32 character responses and then assign the value to a variable which then goes into the Dynamic content for Dataverse.

I hope this makes sense.

Thanks,

Phil

Hi @PhilStanley 

 

If you are looking to get 1 answer from 15 (i.e. only 1 will be complete) you could use the concat() expression with the answers in a compose.

 

DamoBird365_1-1615489104512.png

 

DamoBird365_2-1615489130044.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien

Hi @DamoBird365 

 

Here is a bit more info.

 

This is the output which shows all the answers from Compose.

 

compose.png

 

These are the form questions which I need to find which one is not empty and write it to Dataverse.

 

result.png

 

I hope this helps.

It may need a (not empty) loop to put through a switch statement and then passing it to a variable then onto Dataverse. As mentioned previously, I am new to this so if I am going about it incorrectly then feel free to let me know.

 

Thanks again.

Phil

DamoBird365
Community Champion
Community Champion

Hi @PhilStanley 

 

If only 1 has an answer and 14 are empty you can simply construct a concat expression as per my example above.  Concat will concatenate all of the answers from the 15 strings.  If only 1 is complete, you will end up with the 1 answer and no need to worry about complex switch statements.  Concating an empy string to and empty string gives you nothing and so it will only supply you with the single answer.

 

Go into the expression builder, type concat() and then back to dynamic and select each field you require with a comma between them all.

 

Unless I have completely misunderstood, this makes your life a lot easier and you save the result of the concat back to dataverse.

 

Damien

View solution in original post

Hii @DamoBird365 ,

 

That's a brilliant idea. I would never have thought of that. I will give that a go and if all goes ok then I will come back and "Accept as Solution".

Thanks

Phil

Hi @DamoBird365 ,

 

I wish I had come to you 4 days ago. I am so thankful for your help.

DamoBird365
Community Champion
Community Champion

@PhilStanley - made my day - thanks!  😁  Enjoy.

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

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Users online (2,260)