Hi,
I receive geolocations for my devices on an irregular basis. I want the property to be updated only if the geolocation is actually available in the payload.
But using this template I receive an error everytime, the geolocation is missing.
{{#if working.data.geolocation}}
{{#ne working.data.geolocation.latitude working.data.geolocation.longitude}}
{{working.data.geolocation.latitude}},{{working.data.geolocation.longitude}}
{{/ne}}
{{/if}}
If I set ‘undefined’ in an “else” block, the property is updated with the string “undefined” which is also marked as an error. Setting to “Null Island” (0,0) overwrites the actual GPS position.
What can I do?
Hi @Marco_Bernutz and welcome to the Losant forums!
To properly diagnose the issue here, we’re going to need a few more details. Can you export the workflow file and DM to it me, along with a sample payload?
In the mean time, I recommend you check out the Template Tester feature in our workflow engine. It’s most useful when used in conjunction with the Virtual Button Trigger and the Debug Node to test a variety of payload and node configurations. Also, you may have reviewed this already, but the Conditional Block Helpers page is a very relevant resource for your question.
Once again, thanks for joining us on the Losant forums!
Hi Sebastian, many thanks for your support.
It seems that one cannot use a string template expression (eg. #if, #eq, #ne) within a Device:Set block to set either a measured value (TRUE branch) or a JSON “undefined” if the value is missing (FALSE branch).
Using a Conditional-Block messes up the graph, if there are multiple of such cases/fields.
I am now using a function block to perform the operations and to create the desired result.
Glad to hear you found a workaround using the Function node. I’m still happy to review your workflow and diagnose the issue you’re describing if you’d like. Unfortunately, there aren’t enough details in this thread for me to say what the issue is.
Otherwise, let us know if you have any other questions - we’re here to help!