Azure Logic Apps – A Custom Tracking ID & Service Bus Triggers

Posted: February 2, 2021  |  Categories: Azure
Tags: Logic Apps

I am going to describe my attempts to add a Custom Tracking ID to a Logic App with a Service Bus Trigger. I am stuck and looking for a solution.

The Problem

This Logic App consumes orders from a service bus topic. The Session id of the order on the topic is set to the order number. I want to use this for tracking.

My first attempt set the custom tracking id as shown below. This works when there is an order on the topic and the order number appears as a custom tracking number in Application Insights.

Unfortunately trigger evaluation when there are no orders on the topic fail with this ;

Unable to process template language expressions for trigger ‘When_a_IF_ORDER_1_1_message_is_received_in_a_topic_subscription_(auto-complete)’ at line ‘1’ and column ‘4548’: ‘The template language expression ‘triggerBody()?[‘SessionId’]’ cannot be evaluated because property ‘SessionId’ cannot be selected. Property selection is not supported on values of type ‘String’. Please see for usage details.

If I remove the custom trigger the trigger evaluation is skipped as expected.

A Failed Attempt

Work flow definition language reference says “To reference null properties in an object without a runtime error, use the question mark operator.” Thus I changed the customer tracking id above to @coalesce(triggerBody()?[‘SessionId’],guid()). Once again I got a similar trigger evaluation failure;

The template language expression ‘coalesce(triggerBody()?[‘SessionId’],guid())’ cannot be evaluated because property ‘SessionId’ cannot be selected.

Conclusion – No solution

Does anyone know how to add a custom tracking id to a service bus trigger? It seems to me that if you add one then trigger evaluation always fails when there is no message on the queue or topic. Even testing the object is null with the coalesce function does not help. Is this just a limitation of the service bus trigger?

Postscript – A solution

Wagner Silveira gave a solution.

Thanks. I have learnt that you can use empty. I had tried if(greater … but did not mention that. I think it should work. The final solution for the trigger is

@if (empty(triggerBody()),guid(),triggerBody()?['SessionId'])

BizTalk Server

Over 500+ customers across
30+ countries depend on BizTalk360

Learn More

Manage and monitor serverless
components effortlessly

Learn More
Business Users

Monitor your Business Activity in iPaaS
or Hybrid integration solutions

Learn More

Back to Top