Empty Variables in Veloctiy

I am using a transform to get an attribute value from a source (e.g. Company from UltiPro) and then using if/else velocity statements based on the value in that field. If the user’s source is NELM rather than UltiPro, that value is empty but the velocity errors out. Other than using a firstValid on the Company variable, is there an easier way to handle blank values?

{
“attributes”: {
“Company”: {
“attributes”: {
“attributeName”: “Company”,
“sourceName”: “UltiPro API”
},
“type”: “accountAttribute”
},
“value”: “#if($Company==‘acme’)@acme.com#{else}@othercompany.com#end”
},
“id”: “Email Domain”,
“type”: “static”
}

1 Like

firstValid is the best solution for correcting null values. Here is a simple example that will look for a mail attribute from AD, and if it is not available it will use the static string value none.

{
  "id": "Determine Email",
  "type": "lower",
  "attributes": {
    "input": {
      "type": "firstValid",
      "attributes": {
        "values": [
          {
            "attributes": {
              "attributeName": "mail",
              "sourceName": "Active Directory"
            },
            "type": "accountAttribute"
          },
          {
            "attributes": {
              "value": "none"
            },
            "type": "static"
          }
        ]
      }
    }
  }
}
1 Like