Azure / LogicAppsUX

https://learn.microsoft.com/azure/logic-apps
MIT License
77 stars 84 forks source link

Switch doesn't work properly #6061

Closed Jeroen-Wetzels closed 2 weeks ago

Jeroen-Wetzels commented 2 weeks ago

Describe the Bug with repro steps

I've a workflow with a Switch-action in it. In this switch there are 9 branches and a default branch.

Depending on the "Country"-value it goes to a specific branch and in each branch a variable "CountryCode" will be set.

But in this case the input value is "Netherlands" and the switch goes to the "Netherlands"-branch, but when it sets the CountryCode it uses the value of the "default"-branche.

What type of Logic App Is this happening in?

Consumption (Portal)

Which operating system are you using?

Windows

Are you using new designer or old designer

New Designer

Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "contentVersion": "1.0.0.0",
        "triggers": {
            "Recurrence": {
                "type": "Recurrence",
                "recurrence": {
                    "interval": 12,
                    "frequency": "Month"
                }
            }
        },
        "actions": {
            "Get_Accounts": {
                "type": "ApiConnection",
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['commondataservice']['connectionId']"
                        }
                    },
                    "method": "get",
                    "headers": {
                        "prefer": "odata.include-annotations=*",
                        "accept": "application/json;odata.metadata=full",
                        "organization": "https://liof.crm4.dynamics.com"
                    },
                    "path": "/api/data/v9.1/@{encodeURIComponent(encodeURIComponent('accounts'))}",
                    "queries": {
                        "$select": "accountid,liof_achillesid,wsnl_kvkno",
                        "$filter": "liof_achillesid ne null",
                        "$top": 1
                    }
                },
                "runAfter": {
                    "Update_item": [
                        "Succeeded"
                    ]
                }
            },
            "For_each": {
                "type": "Foreach",
                "foreach": "@body('Get_Accounts')?['value']",
                "actions": {
                    "Get_company": {
                        "type": "Http",
                        "inputs": {
                            "uri": "https://achilles.rvo.nl/api/v1/companies/@{item()?['liof_achillesid']}",
                            "method": "GET",
                            "headers": {
                                "Authorization": "Bearer @{body('Parse_JSON_-_Renew_refresh_token')?['access_token']}",
                                "Connection": "close",
                                "Host": "achilles.rvo.nl"
                            }
                        },
                        "runAfter": {
                            "Set_KvK-nummer": [
                                "Succeeded"
                            ]
                        }
                    },
                    "Parse_company": {
                        "type": "ParseJson",
                        "inputs": {
                            "content": "@body('Get_company')",
                            "schema": {
                                "properties": {
                                    "activityIds": {
                                        "items": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ]
                                        },
                                        "type": "array"
                                    },
                                    "code": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "country": {
                                        "properties": {
                                            "continent": {
                                                "type": [
                                                    "string",
                                                    "null"
                                                ]
                                            },
                                            "id": {
                                                "type": [
                                                    "integer",
                                                    "null"
                                                ]
                                            },
                                            "name": {
                                                "type": [
                                                    "string",
                                                    "null"
                                                ]
                                            }
                                        },
                                        "type": "object"
                                    },
                                    "id": {
                                        "type": "integer"
                                    },
                                    "industryIds": {
                                        "items": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ]
                                        },
                                        "type": "array"
                                    },
                                    "kvkNumber": {
                                        "type": [
                                            "integer",
                                            "null"
                                        ]
                                    },
                                    "name": {
                                        "type": "string"
                                    },
                                    "postalAddress": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "postalCity": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "postalZipCode": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "profile": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "state": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "visitAddress": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "visitCity": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    },
                                    "visitZipCode": {
                                        "type": [
                                            "string",
                                            "null"
                                        ]
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "runAfter": {
                            "Get_company": [
                                "Succeeded"
                            ]
                        }
                    },
                    "Switch_country": {
                        "type": "Switch",
                        "expression": "@body('Parse_company')?['country'].name",
                        "default": {
                            "actions": {
                                "Set_CountryCode_is_Other": {
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "CountryCode",
                                        "value": 100016009
                                    }
                                }
                            }
                        },
                        "cases": {
                            "Netherlands": {
                                "actions": {
                                    "Set_CountryCode_is_Netherlands": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016000
                                        }
                                    }
                                },
                                "case": "Netherlands\n"
                            },
                            "Germany": {
                                "actions": {
                                    "Set_CountryCode_is_Germany": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016001
                                        }
                                    }
                                },
                                "case": "Germany\n"
                            },
                            "Belgium": {
                                "actions": {
                                    "Set_CountryCode_is_Belgium": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016002
                                        }
                                    }
                                },
                                "case": "Belgium\n"
                            },
                            "United_States": {
                                "actions": {
                                    "Set_CountryCode_is_United_States": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016003
                                        }
                                    }
                                },
                                "case": "United States\n"
                            },
                            "United_Kingdom": {
                                "actions": {
                                    "Set_CountryCode_is_United_Kingdom": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016004
                                        }
                                    }
                                },
                                "case": "United Kingdom\n"
                            },
                            "Switzerland": {
                                "actions": {
                                    "Set_CountryCode_is_Switzerland": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016005
                                        }
                                    }
                                },
                                "case": "Switzerland\n"
                            },
                            "China": {
                                "actions": {
                                    "Set_CountryCode_is_China": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016006
                                        }
                                    }
                                },
                                "case": "China\n"
                            },
                            "France": {
                                "actions": {
                                    "Set_CountryCode_is_France": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016007
                                        }
                                    }
                                },
                                "case": "France\n"
                            },
                            "Japan": {
                                "actions": {
                                    "Set_CountryCode_is_Japan": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "CountryCode",
                                            "value": 100016008
                                        }
                                    }
                                },
                                "case": "Japan\n"
                            }
                        },
                        "runAfter": {
                            "kvk-nummer_is_empty": [
                                "Succeeded"
                            ]
                        }
                    },
                    "Update_Account": {
                        "type": "ApiConnection",
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['commondataservice']['connectionId']"
                                }
                            },
                            "method": "patch",
                            "body": {
                                "wsnl_kvkno": "@variables('KvK-nummer')",
                                "liof_land": "@variables('CountryCode')"
                            },
                            "headers": {
                                "prefer": "return=representation,odata.include-annotations=*",
                                "accept": "application/json;odata.metadata=full",
                                "organization": "https://liof.crm4.dynamics.com"
                            },
                            "path": "/api/data/v9.1/@{encodeURIComponent(encodeURIComponent('accounts'))}(@{encodeURIComponent(encodeURIComponent(item()?['accountid']))})"
                        },
                        "runAfter": {
                            "Switch_country": [
                                "Succeeded"
                            ]
                        }
                    },
                    "Send_an_email_(V2)": {
                        "type": "ApiConnection",
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['office365']['connectionId']"
                                }
                            },
                            "method": "post",
                            "body": {
                                "To": "jeroen.wetzels@liof.nl",
                                "Subject": "Kan account niet vinden",
                                "Body": "<p class=\"editor-paragraph\">@{item()?['liof_achillesid']}</p>",
                                "Importance": "Normal"
                            },
                            "path": "/v2/Mail"
                        },
                        "runAfter": {
                            "Get_company": [
                                "Failed",
                                "Skipped",
                                "TimedOut"
                            ]
                        }
                    },
                    "Set_KvK-nummer": {
                        "type": "SetVariable",
                        "inputs": {
                            "name": "KvK-nummer",
                            "value": "@item()?['wsnl_kvkno']"
                        }
                    },
                    "kvk-nummer_is_empty": {
                        "type": "If",
                        "expression": {
                            "and": [
                                {
                                    "equals": [
                                        "@variables('KvK-nummer')",
                                        ""
                                    ]
                                }
                            ]
                        },
                        "actions": {
                            "Set_kvk-nummer_2": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "KvK-nummer",
                                    "value": "@body('Parse_company')?['kvkNumber']"
                                }
                            }
                        },
                        "else": {
                            "actions": {}
                        },
                        "runAfter": {
                            "Parse_company": [
                                "Succeeded"
                            ]
                        }
                    }
                },
                "runAfter": {
                    "Initialize_KvK-nummer": [
                        "Succeeded"
                    ]
                },
                "runtimeConfiguration": {
                    "concurrency": {
                        "repetitions": 1
                    }
                }
            },
            "Get_item": {
                "type": "ApiConnection",
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://liof.sharepoint.com/sites/ICTER'))}/tables/@{encodeURIComponent(encodeURIComponent('2290f695-4459-4747-b994-cf4f634f4a3a'))}/items/@{encodeURIComponent('1')}"
                },
                "runAfter": {}
            },
            "Renew_refresh_token": {
                "type": "Http",
                "inputs": {
                    "uri": "https://achilles.rvo.nl/api/v1/token",
                    "method": "POST",
                    "headers": {
                        "Connection": "close",
                        "Content-Type": "application/json; charset=utf-8",
                        "Host": "achilles.rvo.nl"
                    },
                    "body": {
                        "client_id": "@{body('Get_item')?['ClientID']}",
                        "grant_type": "refresh_token",
                        "refresh_token": "@{body('Get_item')?['RefreshToken']}"
                    }
                },
                "runAfter": {
                    "Get_item": [
                        "Succeeded"
                    ]
                }
            },
            "Parse_JSON_-_Renew_refresh_token": {
                "type": "ParseJson",
                "inputs": {
                    "content": "@body('Renew_refresh_token')",
                    "schema": {
                        "properties": {
                            "access_token": {
                                "type": "string"
                            },
                            "expires_in": {
                                "type": "integer"
                            },
                            "refresh_token": {
                                "type": "string"
                            },
                            "token_type": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {
                    "Renew_refresh_token": [
                        "Succeeded"
                    ]
                }
            },
            "Update_item": {
                "type": "ApiConnection",
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                        }
                    },
                    "method": "patch",
                    "body": {
                        "Title": "@body('Get_item')['Title']",
                        "AccessToken": "@body('Parse_JSON_-_Renew_refresh_token')?['access_token']",
                        "RefreshToken": "@body('Parse_JSON_-_Renew_refresh_token')?['refresh_token']"
                    },
                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://liof.sharepoint.com/sites/ICTER'))}/tables/@{encodeURIComponent(encodeURIComponent('2290f695-4459-4747-b994-cf4f634f4a3a'))}/items/@{encodeURIComponent('1')}"
                },
                "runAfter": {
                    "Parse_JSON_-_Renew_refresh_token": [
                        "Succeeded"
                    ]
                }
            },
            "Initialize_CountryCode": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "CountryCode",
                            "type": "integer"
                        }
                    ]
                },
                "runAfter": {
                    "Get_Accounts": [
                        "Succeeded"
                    ]
                }
            },
            "Initialize_KvK-nummer": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "KvK-nummer",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_CountryCode": [
                        "Succeeded"
                    ]
                }
            }
        },
        "outputs": {},
        "parameters": {
            "$connections": {
                "type": "Object",
                "defaultValue": {}
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "commondataservice": {
                    "id": "/subscriptions/e25da7da-17b1-492b-8c44-2af4a3a52206/providers/Microsoft.Web/locations/westeurope/managedApis/commondataservice",
                    "connectionId": "/subscriptions/e25da7da-17b1-492b-8c44-2af4a3a52206/resourceGroups/TeamInternationaal/providers/Microsoft.Web/connections/commondataservice",
                    "connectionName": "commondataservice"
                },
                "office365": {
                    "id": "/subscriptions/e25da7da-17b1-492b-8c44-2af4a3a52206/providers/Microsoft.Web/locations/westeurope/managedApis/office365",
                    "connectionId": "/subscriptions/e25da7da-17b1-492b-8c44-2af4a3a52206/resourceGroups/TeamInternationaal/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365"
                },
                "sharepointonline": {
                    "id": "/subscriptions/e25da7da-17b1-492b-8c44-2af4a3a52206/providers/Microsoft.Web/locations/westeurope/managedApis/sharepointonline",
                    "connectionId": "/subscriptions/e25da7da-17b1-492b-8c44-2af4a3a52206/resourceGroups/TeamInternationaal/providers/Microsoft.Web/connections/sharepointonline",
                    "connectionName": "sharepointonline"
                }
            }
        }
    }
}

Screenshots or Videos

Image

Image

Image

Browser

Google Chrome Version 130.0.6723.117 (Officiële build) (64-bits)

Additional context

No response