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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Switch function not wo...
Power Automate
Answered

Switch function not working, expecting string and not object

(0) ShareShare
ReportReport
Posted on by 34

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.

Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

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

  • PhilStanley Profile Picture
    34 on at

    Hi @DamoBird365 ,

     

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

  • PhilStanley Profile Picture
    34 on at

    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

  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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

  • PhilStanley Profile Picture
    34 on at

    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 Profile Picture
    8,942 Microsoft Employee on at

    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

  • PhilStanley Profile Picture
    34 on at

    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

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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


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
David_MA Profile Picture

David_MA 245 Super User 2025 Season 2

#2
Expiscornovus Profile Picture

Expiscornovus 207 Most Valuable Professional

#3
trice602 Profile Picture

trice602 185 Super User 2025 Season 2

Last 30 days Overall leaderboard