Microsoft Power Automate "Switch" - Action not matching Case results

1.5k Views Asked by At

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":"[email protected];","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":"[email protected]; [email protected]"},"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":"[email protected];","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":"[email protected]; [email protected]"},"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":"[email protected];","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":"[email protected]; [email protected]"},"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":"[email protected];","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":"[email protected]; [email protected]"},"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":"[email protected];","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":"[email protected]; [email protected]"},"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":"[email protected]","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

1

There are 1 best solutions below

0
On

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": {
                            ...
                            }
                        }
                    }
                }