Math operations in a transform

:bangbang: Please be sure you’ve read the docs and API specs before asking for help. Also, please be sure you’ve searched the forum for your answer before you create a new topic.

Is there a good way to handle mathematical operations in the velocity script part of a transfrom?

I have the logic:

#if($studentExpirationDate > $expirationDate) Student Wins

#elseif($expirationDate > $studentExpirationDate) Employee Wins

#{else}Nobody wins— Empl Exp Date = $expirationDate, Student Exp Date = $studentExpirationDate#end"

It is outputting the value:
Nobody wins— Empl Exp Date = 133525332000000000, Student Exp Date = 133817364000000000

To work around this I think I can do a date math comparison, as they are both in WIN32 format. But I don’t seem to be able to figure out how to convert it to a numerical value and then do a greater than comparison.

Have you tried dateCompare transform?

Where are you doing these calculations? Your example does not looks like it is part of a transform.

As mentioned by @iamnithesh, i would look at the Date Compare transform if both of your values are ISO dates, as that is what is needed for the DateCompare. If they are not, consider using the DateFormat transform to convert the value to the ISO format first.

To handle your case, you may need to nest two DateCompares since you need the 3 options (gt, eq, and lt).

1 Like

Yeah, working on a date compare. But still curious how you might handle math operations in a transform.

The below isn’t working, I suspect it doesn’t like taking the input in the WIN32 format.

My original transform is working without this section, but once I try to test it with this section it starts failing with the studentExpirationDate variable.

"studentEndDateGreater": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateFormat",
                    "attributes": {
                        "input": "$studentExpirationDate",
                        "inputFormat": "EPOCH_TIME_WIN32",
                        "outputFormat": "ISO8601"
                    }
                },
                "secondDate": {
                    "type": "dateFormat",
                    "attributes": {
                        "input": "$expirationDate",
                        "inputFormat": "EPOCH_TIME_WIN32",
                        "outputFormat": "ISO8601"
                    }
                },
                "operator": "gt",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },

Yeah, I only included a sample velocity script from a test transform and not the transform itself.

With my specific use case I only need the greater than, but great point for other use cases.

Good morning Fred,

You can’t put a variable directly into the input, you need to reference it. Something like this:

"input": {
  "type": "reference",
   "attributes": {
    "name": "SF2 - Calculate Formatted StartDate"
   }

1 Like

Thanks Phil!

I ended up referencing the source attributes. I thought I had referenced variables in the past, it didn’t help that the AI bot validated it :slight_smile:

2 Likes

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