Skip to content

Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length') #26

@acieslik

Description

@acieslik

When using this logic app definition the Helper function GetAction will fail, as for some reason an array of actions return instead of one currentAction as the name implies:
Where-Object: C:\Repos\github\logicappdocs_ac\src\Helper.ps1:173:76
Line |
173 | … ($Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($cur …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

(security related data was replaced with fake names or numbers):

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Get_apikey": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['keyvault']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/secrets/@{encodeURIComponent('mykey')}/value"
                },
                "runAfter": {
                    "Initialize_processid": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            },
            "Initialize_apikey": {
                "inputs": {
                    "variables": [
                        {
                            "name": "apikey",
                            "type": "string",
                            "value": "@body('Get_apikey')?['value']"
                        }
                    ]
                },
                "runAfter": {
                    "Get_apikey": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_processid": {
                "inputs": {
                    "variables": [
                        {
                            "name": "processid",
                            "type": "String",
                            "value": "@triggerBody()['processid']"
                        }
                    ]
                },
                "runAfter": {
                    "init_uri": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "async_response": {
                "inputs": {
                    "body": {},
                    "schema": {
                        "properties": {},
                        "type": "object"
                    },
                    "statusCode": 200
                },
                "kind": "Http",
                "runAfter": {
                    "Initialize_apikey": [
                        "Succeeded"
                    ]
                },
                "type": "Response"
            },
            "init_baseuri": {
                "description": "The base uri for sap webservice.",
                "inputs": {
                    "variables": [
                        {
                            "name": "baseUri",
                            "type": "String",
                            "value": "https://sapservices/api/"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "init_uri": {
                "description": "Create the complete request uri for the sap webservice.",
                "inputs": {
                    "variables": [
                        {
                            "name": "uri",
                            "type": "String",
                            "value": "@{variables('baseUri')}@{triggerBody()?['operationName']}"
                        }
                    ]
                },
                "runAfter": {
                    "init_baseuri": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "sap_service_invoke": {
                "actions": {
                    "Invoke_sap_webservice": {
                        "inputs": {
                            "body": {
                                "AccountNumber": "@{triggerBody()?['AccountNumber']}",
                                "EntityId": "@{triggerBody()?['EntityId']}",
                                "EntityLogicalName": "@{triggerBody()?['EntityLogicalName']}",
                                "QuoteId": "@{triggerBody()?['QuoteId']}",
                                "SalesOrg": "@{triggerBody()?['SalesOrg']}",
                                "userId": "@{triggerBody()?['userId']}"
                            },
                            "headers": {
                                "Content-Type": "application/json",
                                "Ocp-Apim-Subscription-Key": "@variables('apikey')",
                                "Ocp-Apim-Trace": "true"
                            },
                            "method": "POST",
                            "retryPolicy": {
                                "type": "none"
                            },
                            "uri": "@variables('uri')"
                        },
                        "runAfter": {},
                        "type": "Http"
                    },
                    "Parse_sap_webservice_response_body": {
                        "inputs": {
                            "content": "@body('Invoke_sap_webservice')",
                            "schema": {
                                "properties": {
                                    "ErrorMessage": {},
                                    "HasOrderBlock": {
                                        "type": "boolean"
                                    },
                                    "Success": {
                                        "type": "boolean"
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "runAfter": {
                            "Invoke_sap_webservice": [
                                "Succeeded"
                            ]
                        },
                        "type": "ParseJson"
                    }
                },
                "runAfter": {
                    "Initialize_apikey": [
                        "Succeeded"
                    ]
                },
                "type": "Scope"
            },
            "sap_service_invoke_failed": {
                "actions": {
                    "update_process_failed": {
                        "inputs": {
                            "body": {
                                "_ownerid_type": "",
                                "test_log": "@{body('Parse_sap_webservice_response_body')?['ErrorMessage']}",
                                "test_processstatus": 135790003
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['commondataservice_1']['connectionId']"
                                }
                            },
                            "method": "patch",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('democrm'))}/tables/@{encodeURIComponent(encodeURIComponent('test_longrunningprocesses'))}/items/@{encodeURIComponent(encodeURIComponent(variables('processid')))}"
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "runAfter": {
                    "sap_service_invoke": [
                        "TimedOut",
                        "Failed"
                    ]
                },
                "type": "Scope"
            },
            "sap_service_invoke_succeeded": {
                "actions": {
                    "update_process_succeeded": {
                        "inputs": {
                            "body": {
                                "_ownerid_type": "",
                                "test_processstatus": 135790002,
                                "test_response": "@{body('Invoke_sap_webservice')}"
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['commondataservice_1']['connectionId']"
                                }
                            },
                            "method": "patch",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('democrm'))}/tables/@{encodeURIComponent(encodeURIComponent('test_longrunningprocesses'))}/items/@{encodeURIComponent(encodeURIComponent(variables('processid')))}"
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "runAfter": {
                    "sap_service_invoke_failed": [
                        "Skipped"
                    ]
                },
                "type": "Scope"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {
                        "properties": {
                            "AccountNumber": {},
                            "EntityId": {
                                "type": "string"
                            },
                            "EntityLogicalName": {
                                "type": "string"
                            },
                            "QuoteId": {
                                "type": "string"
                            },
                            "SalesOrg": {
                                "type": "string"
                            },
                            "UserId": {
                                "type": "string"
                            },
                            "operationName": {
                                "type": "string"
                            },
                            "processId": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "commondataservice_1": {
                    "connectionId": "/subscriptions/12378888-ce3e-456b-92c9-54e214015111/resourceGroups/test/providers/Microsoft.Web/connections/commondataservice",
                    "connectionName": "commondataservice",
                    "id": "/subscriptions/12378888-ce3e-456b-92c9-54e214015111/providers/Microsoft.Web/locations/westeurope/managedApis/commondataservice"
                },
                "keyvault": {
                    "connectionId": "/subscriptions/12378888-ce3e-456b-92c9-54e214015111/resourceGroups/test/providers/Microsoft.Web/connections/keyvault",
                    "connectionName": "keyvault",
                    "id": "/subscriptions/12378888-ce3e-456b-92c9-54e214015111/providers/Microsoft.Web/locations/westeurope/managedApis/keyvault"
                }
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions