Pipeline Rule - Using Absolute value (no negative)

Hi,

I am trying to create a Rule that calculates the difference between the Number value of 2 fields, and have this difference set in a new field. We need to have this value as Positive - basically have the Absolute value.

It looks something like this:

rule "Check Diff"
when
  has_field("FieldName")
then
  let Value1 = $message.Field1;
  let Value2 = $message.Field2;
  let Diff = Value1 - Value2;
  set_field("TotalDiff", Diff);
end

In this case, if Field2 is larger than Field1, the Diff value with be negative.
I tried using the | symbol ( |Value| ), on the Parameter value in SET row, but it shows error.

I could not test this, so not sure if what I wrote is even correct :slight_smile:

Would appreciate any assistance.
Let me know if you need additional info.

Thanks

maybe convert to text, only take digits, then change it to a long as you are setting the field?

 let Diff = regex("\\d+", to_string(Diff));
 set_field("TotalDiff", to_long(Diff));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.