0

i have a azure logic app. in a condition it checks for four payment methods 'Cash' 'Cheque' 'Credit Card' 'Transfer'. then it set to a variable in a following step. if it is not a payment method from above four it shows an error saying ' InvalidTemplate. The 'start index' for function 'substring' must be equal to or greater than zero and must be less than '1' which is the length of the string.https://aka.ms/logicexpressions#substring' and then the logic app fails. its okay even the payment method is incorrect the logic app should flow

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Aruna Prabhath
  • 206
  • 2
  • 10

1 Answers1

0

I have reproduced in my environment and got expected results as below:

Here I initialized a blank variable and then done by using below design.

Design:

enter image description here

Then:

enter image description here

Used True False in Conditions:

enter image description here

Code View:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@body('Parse_JSON')?['get']",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Condition": {
                "actions": {
                    "Append_to_string_variable": {
                        "inputs": {
                            "name": "var",
                            "value": "Cash"
                        },
                        "runAfter": {},
                        "type": "AppendToStringVariable"
                    }
                },
                "expression": {
                    "and": [
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Cheque"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "CreditCard"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Transfer"
                                ]
                            }
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded",
                        "Failed"
                    ]
                },
                "type": "If"
            },
            "Condition_2": {
                "actions": {
                    "Append_to_string_variable_2": {
                        "inputs": {
                            "name": "var",
                            "value": "Cheque"
                        },
                        "runAfter": {},
                        "type": "AppendToStringVariable"
                    }
                },
                "expression": {
                    "and": [
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Cash"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "CreditCard"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Transfer"
                                ]
                            }
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded",
                        "Failed"
                    ]
                },
                "type": "If"
            },
            "Condition_3": {
                "actions": {
                    "Append_to_string_variable_3": {
                        "inputs": {
                            "name": "var",
                            "value": "CreditCard"
                        },
                        "runAfter": {},
                        "type": "AppendToStringVariable"
                    }
                },
                "expression": {
                    "and": [
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Cheque"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Cash"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Transfer"
                                ]
                            }
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Condition_4": {
                "actions": {
                    "Append_to_string_variable_4": {
                        "inputs": {
                            "name": "var",
                            "value": "Transfer"
                        },
                        "runAfter": {},
                        "type": "AppendToStringVariable"
                    }
                },
                "expression": {
                    "and": [
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Cash"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "CreditCard"
                                ]
                            }
                        },
                        {
                            "not": {
                                "equals": [
                                    "@outputs('Compose')",
                                    "Cheque"
                                ]
                            }
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@triggerBody()",
                    "schema": {
                        "properties": {
                            "get": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Output:

If Sent Transfer as below:

enter image description here

enter image description here

Output If sent CreditCard:

enter image description here

Output If sent Cash:

enter image description here

Output If sent Cheque:

enter image description here

Here used runAfter Failed Succeeded for conditions(inside conditions used append variable which was initialized empty at first) in design, you can clearly replicate using code( code view) and get to know what the functionality is.

RithwikBojja
  • 5,069
  • 2
  • 3
  • 7