Pradeep
Pradeep

Reputation: 5530

LogicApp - The template language function 'contains' expects its first argument 'collection' to be a string. The provided value is of type 'Null'

I have created an Azure Logic App with the Azure Service Bus Queue Trigger (When a message is received in a queue (auto-complete)) for re-processing dead letter queue messages.

In the same Logic App, I’m validating the dead letter message with DeadLetterReason and DeadLetterErrorDescription properties values and then posting message to active queue. But for the few dead letter messages doesn’t contains the DeadLetterErrorDescription property name and value.

Validation code in the logic app:

 "expression": {
                "or": [
                    {
                        "equals": [
                            "@triggerBody()?['Properties']?['DeadLetterReason']",
                            "TTLExpiredException"
                        ]
                    },
                    {
                        "and": [
                            {
                                "not": {
                                    "equals": [
                                        "@triggerBody()?['Properties']?['DeadLetterReason']",
                                        200
                                    ]
                                }
                            },
                            {
                                "not": {
                                    "contains": [
                                        "@triggerBody()?['Properties']?['DeadLetterErrorDescription']",
                                        "NotFoundException"
                                    ]
                                }
                            }
                        ]
                    }
                ]
            },

Error:

InvalidTemplate. Unable to process template language expressions for action 'Validate_the_DLQ_message_reason_and_description' at line '1' and column '3467': 'The template language function 'contains' expects its first argument 'collection' to be a dictionary (object), an array or a string. The provided value is of type 'Null'.'.

Validation logic:

  1. Need to be verify the DeadLetterReason and DeadLetterErrorDescription properties from Service Bus queue trigger properties.
  2. If the above properties exists, then I need to validate the values of those properties.

So, please suggest me how to verify the above property name exists in the received dead letter message or not.

Upvotes: 0

Views: 5158

Answers (1)

10p
10p

Reputation: 6768

Try using the coalesce function to replace null with an empty string:

"expression": {
    "or": [
        {
            "equals": [
                "@coalesce(triggerBody()?['Properties']?['DeadLetterReason'], '')",
                "TTLExpiredException"
            ]
        },
        {
            "and": [
                {
                    "not": {
                        "equals": [
                            "@coalesce(triggerBody()?['Properties']?['DeadLetterReason'], '')",
                            "200"
                        ]
                    }
                },
                {
                    "not": {
                        "contains": [
                            "@coalesce(triggerBody()?['Properties']?['DeadLetterErrorDescription'], '')",
                            "NotFoundException"
                        ]
                    }
                }
            ]
        }
    ]
},

Upvotes: 3

Related Questions