Can't we use integers in transforms?

I can’t seem to do basic integer comparison in a transform. There is no error thrown but there isn’t a value generated either. What am I missing?

Transform below:

    "name": "Determine User Risk",
    "type": "static",
    "attributes": {
        "riskScore": {
            "type": "firstValid",
            "attributes": {
                "values": [
                    {
                        "attributes": {
                            "attributeName": "RiskScore",
                            "sourceName": "Exabeam Advanced Analytics"
                        },
                        "type": "accountAttribute"
                    },
                    {
                        "attributes": {
                            "value": 0
                        },
                        "type": "static"
                    }
                ]
            }
        },
        "value": "#if($riskScore > 60)Yes#elseNo#end"
    },
    "internal": false
}

Hello @sushant1,

It looks like the static transform makes your riskScore value a string.

Here is a workaround to convert it back to an Integer for comparison.

{
   "name": "Determine User Risk",
   "type": "static",
   "attributes": {
   	"riskScore": {
   		"type": "firstValid",
   		"attributes": {
   			"values": [{
   					"attributes": {
   						"attributeName": "RiskScore",
   						"sourceName": "Exabeam Advanced Analytics"
   					},
   					"type": "accountAttribute"
   				},
   				{
   					"attributes": {
   						"value": 0
   					},
   					"type": "static"
   				}
   			]
   		}
   	},
   	"value": "#set($Integer = 0)#if($Integer.parseInt($riskScore) > 60)Yes#{else}No#end"
   },
   "internal": false
}
1 Like

Thanks Tyler, this seems to be working fine.
What’s strange is the attribute I am using is defined as an int on the source schema, but even then it was treated as a string within the transform.

I’ll take this method of parsing to be the standard approach for all use cases involving integer value transforms in the future (until there’s a better way!).

1 Like