Skip to main content Skip to footer

Search Crosser Knowledge Base

Checking if a property is missing

Sometimes you receive data where a property may be present, but sometimes it is missing. To not create issues with the following modules that expect this property to be present you may want to ensure that it’s always present by adding it with a default value whenever it’s missing. Another scenario is that you want to take different actions when the property is there and when it’s not.

Both of these cases require that we can detect whether a property is missing or not. The obvious choice would be to use message filters. Unfortunately there is no filter condition for ‘missing property’. Until that is available there is a trick you can use to trigger on this condition.

Let’s say we want to check if the property ‘test’ is present. If it is we just pass it along, if it’s not we want to add it with a default value of ‘default’. To do that we add a Property Mapper module where we add a message filter that is guaranteed to be false if the property exists. For example, if you expect string values on that property you can use the ‘Is Numeric’ filter. In this example we use the ‘Null’ filter which will be false for any valid strings. This also means that we will replace any null values with a default string.

With this filter we will block any message that contains valid data, and pass through messages where the ‘test’ property is missing or where the value is null. Not really what we want! Now comes the trick.

To get the behavior we want we first modify our filter by enabling the ‘Bypass message to next module in flow if filters do not match’ setting. Then any message with valid data will be passed along without modifications. Next we enable the ‘Missing ok’ setting. This will cause the filter to be true if the property is missing, in addition to the value being null. Finally we add the default value on the Settings tab in the ‘Add Property’ section, by assigning the value ‘default’ to the ‘test’ property. If it doesn’t exist it will be added, if it contains null it will be overridden. Problem solved!

Crosser Tech Tips 99 Crosser Tech Tip 99 - 2

Example:

Crosser Tech Tip 99 - Example

About the author

Goran Appelquist

Göran has 20 years experience in leading technology teams. He’s the lead architect of our end-to-end solution and is extremely focused in securing the lowest possible Total Cost of Ownership for our customers.

"Hidden Lifecycle (employee) cost can account for 5-10 times the purchase price of software. Our goal is to offer a solution that automates and removes most of the tasks that is costly over the lifecycle.

My career started in the academic world where I got a PhD in physics by researching large scale data acquisition systems for physics experiments, such as the LHC at CERN. After leaving academia I have been working in several tech startups in different management positions over the last 20 years.

In most of these positions I have stood with one foot in the R&D team and another in the product/business teams. My passion is learning new technologies, use it to develop innovative products and explain the solutions to end users, technical or non-technical."