2

I have a flow with a switch control triggered by a form, where the switch depends on the answer to one of the questions (Single Choice + "Other" with an empty space, hence the "Default" case).

There is also Compose action to replace spacing before the switch action:

replace(variables('aplicabilidade'), ' ', '')

("aplicabilidade" being the value extracted from the Form) and then I manually applied the same replacement to the values before adding them to the switch control. However, while the Case is correctly identified, the Flow does not follow-up with the correct action:

Case 4 returns True but Default Action occurs instead

In my original post in the Power Automate forum a user suggested using Trim instead of Replace, but it not change the result. Since (for other than spacing) the values are literally copy-paste from the Forms to the Switch, Case Sensitivity should not be an issue.

I tested the form with an answer that I know matches Case 4, and when the Flow is run it indeed identifies it as matching; however, instead of following the action intended in that Case, it triggers the Default Case action. "Trim" instead of "Replace" does not yield different results

Any ideas?

I attempted to use a Switch Control on a Power Automate Flow to send different emails based on an answer in a Microsoft Forms. However, the flow always triggers the default action even when correctly matching any of the existing Cases.

EDIT: As requested, json code that I was able to extract from Microsoft Flow Platform: definition.json

"name":"10fe749a-1fad-4da7-a482-630fc9e4d102","id":"/providers/Microsoft.Flow/flows/10fe749a-1fad-4da7-a482-630fc9e4d102","type":"Microsoft.Flow/flows","properties":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_logicflows","displayName":"Sugestões MC","definition":{"metadata":{"workflowEntityId":null,"processAdvisorMetadata":null,"flowclientsuspensionreason":"None","flowclientsuspensiontime":null,"creator":{"id":"f9028ef6-5f90-4c4b-a97e-3b027eeeea8b","type":"User","tenantId":"f9082694-5379-4912-bbe1-1c5e9b6737d7"},"provisioningMethod":"FromDefinition","failureAlertSubscription":true,"clientLastModifiedTime":"2022-03-24T15:00:54.6466915Z"},"$schema":"https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#","contentVersion":"1.0.0.0","parameters":{"$connections":{"defaultValue":{},"type":"Object"},"$authentication":{"defaultValue":{},"type":"SecureObject"}},"triggers":{"When_a_new_response_is_submitted":{"splitOn":"@triggerOutputs()?['body/value']","metadata":{"operationMetadataId":"6b49d155-7960-482f-8ae4-7d0b4b87f316"},"type":"OpenApiConnectionWebhook","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_microsoftforms","connectionName":"shared_microsoftforms","operationId":"CreateFormWebhook"},"parameters":{"form_id":"lCYI-XlTEkm74Rxem2c312Y6IcYaoPlGrOot18luu5lUOEUzN00wV1c0UFBPUkxONFhVWVJLR0RaNCQlQCN0PWcu"},"authentication":"@parameters('$authentication')"}}},"actions":{"Switch":{"runAfter":{"Compose":["Succeeded"]},"cases":{"Case":{"case":"InformaçãoTécnico-CientíficadeMedicamentos\n","actions":{"Send_an_email_notification_(V3)_6":{"runAfter":{},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_sendmail","connectionName":"shared_sendmail","operationId":"SendEmailV3"},"parameters":{"request/to":"XXX@XXX.XX;","request/subject":"MC - Nova Sugestão ","request/text":"<p>Bom dia,<br>\n<br>\nFoi efetuada a seguinte sugestão no formulário de Melhoria Contínua:<br>\n<br>\nTema: @{outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']}<br>\nDetalhe: @{outputs('Get_response_details_2')?['body/r31fe96bb0b4a431896902e60a110d3f2']}<br>\nSugerida por: @{outputs('Get_response_details_2')?['body/r0a0b849bba0b4c7f9da5734602f6aefb']}<br>\n<br>\nSolicitamos análise e follow-up do pedido com a maior brevidade possível.<br>\n<br>\nAtentamente,</p>","request/cc":"XX@XX.XX; XX@XX.XX"},"authentication":"@parameters('$authentication')"}}}},"Case_2":{"case":"IntervençõesemSaúde\n","actions":{"Send_an_email_notification_(V3)_5":{"runAfter":{},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_sendmail","connectionName":"shared_sendmail","operationId":"SendEmailV3"},"parameters":{"request/to":"XX@XX.XX;","request/subject":"MC - Nova Sugestão ","request/text":"<p>Bom dia,<br>\n<br>\nFoi efetuada a seguinte sugestão no formulário de Melhoria Contínua:<br>\n<br>\nTema: @{outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']}<br>\nDetalhe: @{outputs('Get_response_details_2')?['body/r31fe96bb0b4a431896902e60a110d3f2']}<br>\nSugerida por: @{outputs('Get_response_details_2')?['body/r0a0b849bba0b4c7f9da5734602f6aefb']}<br>\n<br>\nSolicitamos análise e follow-up do pedido com a maior brevidade possível.<br>\n<br>\nAtentamente,</p>","request/cc":"XX@XX.XX; XX@XX.XX"},"authentication":"@parameters('$authentication')"}}}},"Case_3":{"case":"LiteraciaemSaúde\n","actions":{"Send_an_email_notification_(V3)_4":{"runAfter":{},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_sendmail","connectionName":"shared_sendmail","operationId":"SendEmailV3"},"parameters":{"request/to":"XX@XX.XX;","request/subject":"MC - Nova Sugestão ","request/text":"<p>Bom dia,<br>\n<br>\nFoi efetuada a seguinte sugestão no formulário de Melhoria Contínua:<br>\n<br>\nTema: @{outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']}<br>\nDetalhe: @{outputs('Get_response_details_2')?['body/r31fe96bb0b4a431896902e60a110d3f2']}<br>\nSugerida por: @{outputs('Get_response_details_2')?['body/r0a0b849bba0b4c7f9da5734602f6aefb']}<br>\n<br>\nSolicitamos análise e follow-up do pedido com a maior brevidade possível.<br>\n<br>\nAtentamente,</p>","request/cc":"XX@XX.XX; XX@XX.XX"},"authentication":"@parameters('$authentication')"}}}},"Case_4":{"case":"Serviço de Consultas\n","actions":{"Send_an_email_notification_(V3)_3":{"runAfter":{},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_sendmail","connectionName":"shared_sendmail","operationId":"SendEmailV3"},"parameters":{"request/to":"XX@XX.XX;","request/subject":"MC - Nova Sugestão ","request/text":"<p>Bom dia,<br>\n<br>\nFoi efetuada a seguinte sugestão no formulário de Melhoria Contínua:<br>\n<br>\nTema: @{outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']}<br>\nDetalhe: @{outputs('Get_response_details_2')?['body/r31fe96bb0b4a431896902e60a110d3f2']}<br>\nSugerida por: @{outputs('Get_response_details_2')?['body/r0a0b849bba0b4c7f9da5734602f6aefb']}<br>\n<br>\nSolicitamos análise e follow-up do pedido com a maior brevidade possível.<br>\n<br>\nAtentamente,</p>","request/cc":"XX@XX.XX; XX@XX.XX"},"authentication":"@parameters('$authentication')"}}}},"Case_5":{"case":"Geral/GestãodoCEDIME\n","actions":{"Send_an_email_notification_(V3)_2":{"runAfter":{},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_sendmail","connectionName":"shared_sendmail","operationId":"SendEmailV3"},"parameters":{"request/to":"XX@XX.XX;","request/subject":"MC - Nova Sugestão ","request/text":"<p>Bom dia,<br>\n<br>\nFoi efetuada a seguinte sugestão no formulário de Melhoria Contínua:<br>\n<br>\nTema: @{outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']}<br>\nDetalhe: @{outputs('Get_response_details_2')?['body/r31fe96bb0b4a431896902e60a110d3f2']}<br>\nSugerida por: @{outputs('Get_response_details_2')?['body/r0a0b849bba0b4c7f9da5734602f6aefb']}<br>\n<br>\nSolicitamos análise e follow-up do pedido com a maior brevidade possível.<br>\n<br>\nAtentamente,</p>","request/cc":"XX@XX.XX; XX@XX.XX"},"authentication":"@parameters('$authentication')"}}}}},"default":{"actions":{"Send_an_email_notification_(V3)_7":{"runAfter":{},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_sendmail","connectionName":"shared_sendmail","operationId":"SendEmailV3"},"parameters":{"request/to":"XX@XX.XX","request/subject":"MC - Nova Sugestão ","request/text":"<p>Bom dia,<br>\n<br>\nFoi efetuada a seguinte sugestão no formulário de Melhoria Contínua:<br>\n<br>\nTema: @{outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']}<br>\nDetalhe: @{outputs('Get_response_details_2')?['body/r31fe96bb0b4a431896902e60a110d3f2']}<br>\nSugerida por: @{outputs('Get_response_details_2')?['body/r0a0b849bba0b4c7f9da5734602f6aefb']}<br>\n<br>\nSolicitamos análise e follow-up do pedido com a maior brevidade possível.<br>\n<br>\nAtentamente,</p>"},"authentication":"@parameters('$authentication')"}}}},"expression":"@outputs('Compose')","metadata":{"operationMetadataId":"91e61dbb-4330-4958-b9b0-234c88e46269"},"type":"Switch"},"Initialize_variable":{"runAfter":{},"metadata":{"operationMetadataId":"2b93713b-f1c3-4e32-a45d-e7f92d417601"},"type":"InitializeVariable","inputs":{"variables":[{"name":"aplicabilidade","type":"string"}]}},"Get_response_details_2":{"runAfter":{"Initialize_variable":["Succeeded"]},"metadata":{"operationMetadataId":"a09d568b-4d47-4c19-9973-6822901883b3"},"type":"OpenApiConnection","inputs":{"host":{"apiId":"/providers/Microsoft.PowerApps/apis/shared_microsoftforms","connectionName":"shared_microsoftforms","operationId":"GetFormResponseById"},"parameters":{"form_id":"lCYI-XlTEkm74Rxem2c312Y6IcYaoPlGrOot18luu5lUOEUzN00wV1c0UFBPUkxONFhVWVJLR0RaNCQlQCN0PWcu","response_id":"@triggerOutputs()?['body/resourceData/responseId']"},"authentication":"@parameters('$authentication')"}},"Set_variable":{"runAfter":{"Get_response_details_2":["Succeeded"]},"metadata":{"operationMetadataId":"70ac8adb-8da6-462d-afa0-1a5ef8db7ccc"},"type":"SetVariable","inputs":{"name":"aplicabilidade","value":"@outputs('Get_response_details_2')?['body/rf479dcadc3884bf09c7c7ad0bb15dfa9']"}},"Compose":{"runAfter":{"Set_variable":["Succeeded"]},"metadata":{"operationMetadataId":"e12e505a-c214-465a-90a5-f8e1f6028f20"},"type":"Compose","inputs":"@trim(variables('aplicabilidade'))"}}},"connectionReferences":{"shared_sendmail":{"connectionName":"shared-sendmail-fbcdc7a1-f228-45b6-8ec5-53f0f421e355","source":"Embedded","id":"/providers/Microsoft.PowerApps/apis/shared_sendmail","tier":"NotSpecified"},"shared_microsoftforms":{"connectionName":"shared-microsoftform-9b29b94d-94d8-434e-9909-861cecd152f4","source":"Embedded","id":"/providers/Microsoft.PowerApps/apis/shared_microsoftforms","tier":"NotSpecified"}},"flowFailureAlertSubscribed":false}}

apisMap.json

{"shared_sendmail":"75acecb3-ef37-4d57-99e2-37af8154d7db","shared_microsoftforms":"5ccd7725-e205-445d-9d1f-9b28a19e8263"}

connectionsMap.json

{"shared_sendmail":"d3995a2b-3566-48f9-b4d4-13a8c8d0d01c","shared_microsoftforms":"9fe07a7e-3104-4c22-a9ec-bc81d18469f0"}

EDIT 2:

"When a new response is submitted"

{
"inputs": {
    "host": {
        "connectionName": "shared_microsoftforms",
        "operationId": "CreateFormWebhook",
        "apiId": "/providers/Microsoft.PowerApps/apis/shared_microsoftforms"
    },
    "parameters": {
        "form_id": "lCYI-XlTEkm74Rxem2c312Y6IcYaoPlGrOot18luu5lUOEUzN00wV1c0UFBPUkxONFhVWVJLR0RaNCQlQCN0PWcu"
    },
    "authentication": "@parameters('$authentication')"
},
"metadata": {
    "operationMetadataId": "6b49d155-7960-482f-8ae4-7d0b4b87f316"
},
"splitOn": "@triggerOutputs()?['body/value']"

}

And then "Get response details":

{
"inputs": {
    "host": {
        "connectionName": "shared_microsoftforms",
        "operationId": "GetFormResponseById",
        "apiId": "/providers/Microsoft.PowerApps/apis/shared_microsoftforms"
    },
    "parameters": {
        "form_id": "lCYI-XlTEkm74Rxem2c312Y6IcYaoPlGrOot18luu5lUOEUzN00wV1c0UFBPUkxONFhVWVJLR0RaNCQlQCN0PWcu",
        "response_id": "@triggerOutputs()?['body/resourceData/responseId']"
    },
    "authentication": "@parameters('$authentication')"
},
"metadata": {
    "operationMetadataId": "a09d568b-4d47-4c19-9973-6822901883b3"
}

}

EDIT 3: Data from run history "When a new response is submitted":

{"headers":{"Expect":"100-continue","Host":"prod-214.westeurope.logic.azure.com","X-CorrelationId":"ee542f19-e358-4f9d-8b6f-9b8e823d2b04","Content-Length":"267","Content-Type":"application/json; charset=utf-8"},"body":{"webhookId":"cb5188c2-c861-4722-92cd-cbd942baeb10","eventType":"ResponseAdded","resourceData":{"formId":"lCYI-XlTEkm74Rxem2c312Y6IcYaoPlGrOot18luu5lUOEUzN00wV1c0UFBPUkxONFhVWVJLR0RaNCQlQCN0PWcu","responseId":3},"eventTime":"2022-03-24T10:24:04.1798293Z"}}

"Get Response Details"

  {  "responder": "anonymous",
  "submitDate": "3/24/2022 10:24:03 AM",
  "r0a0b849bba0b4c7f9da5734602f6aefb": "João Peres",
  "rf479dcadc3884bf09c7c7ad0bb15dfa9": "Serviço de Consultas",
  "r31fe96bb0b4a431896902e60a110d3f2": "texttexttext"
}

I was not able to extract any more code, as the "Show raw outputs" window is blank: enter image description here

enter image description here

JoaoPeres
  • 21
  • 3
  • Did you get any results by not using a Compose action and directly check it with the switch? The compose doesn't seem to be the problem for me. – ojonasplima Mar 25 '22 at 17:45
  • @osfresia I did not initially have the Compose action in the flow; I added it after noticing that sometimes the variable would assume an extra space or return (\n) after the text (in spite of the question in the form never changing, as it has always been a single choice question). By forcing the removal of spaces I was able to prevent not matching "Serviço de Consultas " with "Serviço de Consultas" – JoaoPeres Mar 25 '22 at 18:17
  • To really help, we need the JSON (or whatever) that forms the basis of what you’re doing. Can you paste it here whilst also obfuscating/masking any sensitive data? – Skin Mar 25 '22 at 20:17
  • @Skin I have never worked with JSON, but I was able to extract the Flow from the Power Automate Platform and it contained 3 different .json files - I've edited the OP to add the code there while replacing e-mail addresses with xx@xx.pt – JoaoPeres Mar 26 '22 at 16:08
  • No, sorry, I think you’ve misunderstood me. The “get response details” from the MS forms submission, that’s a json payload, no? If it is, we need it so we can replicate the issue. I need the data that you’re switch function is evaluating. – Skin Mar 26 '22 at 20:38
  • @Skin my bad. I've added the code for both the "When a new response is submitted" and the "Get response details" blocks – JoaoPeres Mar 28 '22 at 08:14
  • No, I don't want the definition of the logic app, I need the data that comes from the response. Where's the JSON that has the `aplicabilidade` variable in it? – Skin Mar 28 '22 at 08:41
  • Sorry, I really do not know much about JSON. I have added the code I was able to extract from my attempted run – JoaoPeres Mar 28 '22 at 17:41

1 Answers1

1

All of your case statements have a line break at the end.

                "Case_4": {
                    "case": "Serviço de Consultas\n",
                    "actions": {
                        "Send_an_email_notification_(V3)_3": {
                            ...
                            }
                        }
                    }
                }
Eric
  • 11
  • 1