If else in transform script

Hi Sailors,

Below is my transform to determine when a comma is needed, but its pop error, wonder which part of my transform is incorrect.

Expected result:

If both value from JDBC’s USERTYPE and HR Source USERTYPE is not null, the result should be: Value1,Value

{
  "name": "Transform for businessCategory value V5",
  "type": "static",
  "attributes": {
    "arType": {
      "type": "accountAttribute",
      "attributes": {
        "sourceName": "JDBC",
        "attributeName": "USER_TYPE"
      }
    },
    "hrType": {
      "type": "accountAttribute",
      "attributes": {
        "sourceName": "HR Source",
        "attributeName": "USER_TYPE"
      }
    },
    "value": "#if($arType!=null && $hrType!=null)$arType,$hrType#elseif($arType!=null)$arType#elseif($hrType!=null)$hrType#else\"\"#end"
  }
}

Hi @Bernardc
can you try this
“value”: “#if($arType && $hrType)$arType,$hrType#elseif($arType)$arType#elseif($hrType)$hrType#else\”\“#end
I tried it from my end and it worked fine

Thanks & reagrds
Tulasi

Looks like cannot have $variiable!=null in the value

Hi

Give a try with the below code

“value”: “#if($arType && $arType != ‘’ && $hrType && $hrType != ‘’)$arType,$hrType#elseif($arType && $arType != ‘’)$arType#elseif($hrType && $hrType != ‘’)$hrType#else""#end

Regards
SathishKumar N

Correct. maybe The Velocity template does not support direct comparisons to null in its syntax

You can try also and make sure that attributes mentionned are present in your account schemas :

{
  "name": "Transform for businessCategory value V5",
  "type": "static",
  "attributes": {
    "arType": {
      "type": "accountAttribute",
      "attributes": {
        "sourceName": "JDBC",
        "attributeName": "USER_TYPE"
      }
    },
    "hrType": {
      "type": "accountAttribute",
      "attributes": {
        "sourceName": "HR Source",
        "attributeName": "USER_TYPE"
      }
    },
    "value": "#if($arType && $hrType)$arType,$hrType#elseif($arType)$arType#elseif($hrType)$hrType#else#end"
  }
}

Hi @Bernardc With any kind of NULL comparison, it’s best to wrap your attribute values in a firstValid transform with it returning a static value of, say, “NULL” if the attribute value is not found. That way your IF becomes a simple if not (a="NULL" or b="NULL") (that’s pseudo code not velocity template)