Sum of 2 results returns error if one results is null

I am trying to make a sum similar to Sum in the same field - #5 by MutedJam

But I have 2 result fields, in the SET action I created to make the sum, I added:

{{ $node[“CL2”].json[“results1”] + $node[“CL”].json[“results”] }}

It works fine when both sides have results, but when one the results is null or flow didn’t run because it had no results, it then returns an error instead of just the value of the one that had results.

What is the best approach to solve this? Thank you very much in advance.

If you want null to be 0 , you can use javascript oneline if ,like this

{{ ( $node[“CL2”].json[“results1”] ) === null ? 0 : $node[“CL2”].json[“results1”] + ( $node[“CL”].json[“results”] ) === null ? 0 : $node[“CL”].json[“results”] }}

( $node[“CL2”].json[“results1”] ) === null ? 0 : $node[“CL2”].json[“results1”] will check if $node[“CL2”].json[“results1”] is 0 or null , if true then set it to 0, else will be origin value of $node[“CL2”].json[“results1”]

1 Like