Search code examples
azure-logic-appsazure-logic-app-standard

Service Bus Trigger Property mapped to custom tracking id with expression


Standard Logic App using Shared Service Bus Trigger (https://learn.microsoft.com/en-gb/connectors/servicebus/#when-a-message-is-received-in-a-topic-subscription-(auto-complete)

I have the following expression in the Custom Tracking Id under Settings->Tracking of the trigger @{triggerBody()?['Properties']?['clientTrackingId']}

Each time the trigger is fired it causes the following exception if there is no message. I assume is polls service bus to see if there are messages.

Unable to process template language expressions for trigger 'When_a_message_is_received_in_get-survey-responses' at line '1' and column '8804': 'The template language expression 'triggerBody()?['Properties']?['clientTrackingId']' cannot be evaluated because property 'Properties' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

It works fine when there is a valid message.

Has anyone come up with an equivalent expression that does not cause an exception?

I tried @{coalesce(triggerBody()?['Properties']?['clientTrackingId'], workflow().run.name)} but no joy


Solution

  • Found a solution https://www.connected-pawns.com/2021/02/02/azure-logic-apps-a-custom-tracking-id-service-bus-triggers/

    @{if(empty(triggerBody()),guid(),triggerBody()?['Properties']?['clientTrackingId'])}