Skip to main content
vikashk739
July 29, 2022
Solved

Expression rule to format address

  • July 29, 2022
  • 4 replies
  • 0 views

I am querying data to get address but when the value is null I am getting ",,,,,". How to remove this comma if fields are not there

trim(concat(
          property(local!address,"fullName",null),
          property(local!address,"buildingNumber",null) & ", " & property(local!address,"streetName",null) & ", " & property(local!address,"district",null) &", "&
          property(local!address,"unitCode",null) &", " &
          property(local!address,"cityName",null) & ", " & property(local!address,"zipCode",null)
        )
        )

Best answer by harshitb6843

There are two ways of doing it. 
The longer and more reliable way is to check every property statement for null and if it is null, then do not pass the entire statement rather just pass an empty string. 

trim(
  concat(
    property(local!address, "fullName", null),
    if(
      a!isNullOrEmpty(
        property(local!address, "buildingNumber", null)
      ),
      "",
      property(local!address, "buildingNumber", null) & ", "
    )
  )
)

The shorter way is just to substitute ",," with "" so that whenever a value is skipped, you can just replace the entire block. It has some exception cases tho. Like when 1 out of 3-4 property functions is not returning the statement.. In that case, it will remove all the commas between the two. 

substitute(trim(",,,,,,"), ",,", "")

Or you can use the joinarray. 

4 replies

harshitb6843
July 29, 2022

There are two ways of doing it. 
The longer and more reliable way is to check every property statement for null and if it is null, then do not pass the entire statement rather just pass an empty string. 

trim(
  concat(
    property(local!address, "fullName", null),
    if(
      a!isNullOrEmpty(
        property(local!address, "buildingNumber", null)
      ),
      "",
      property(local!address, "buildingNumber", null) & ", "
    )
  )
)

The shorter way is just to substitute ",," with "" so that whenever a value is skipped, you can just replace the entire block. It has some exception cases tho. Like when 1 out of 3-4 property functions is not returning the statement.. In that case, it will remove all the commas between the two. 

substitute(trim(",,,,,,"), ",,", "")

Or you can use the joinarray. 

vikashk739
July 29, 2022

Hi Harshit, the Joinarray function worked

July 29, 2022

You can use joinarray function like below

joinarray(
  {
    property(local!address, "fullName", null),
    property(local!address, "buildingNumber", null),
    property(local!address, "streetName", null),
    property(local!address, "district", null),
    property(local!address, "unitCode", null),
    property(local!address, "cityName", null),
    property(local!address, "zipCode", null)
  },
  ", "
)

July 29, 2022

Please try to use joinArray.

joinarray(
    {
      property(local!address, "fullName", null),
      property(local!address, "buildingNumber", null),
      property(local!address, "streetName", null),
      property(local!address, "district", null),
      property(local!address, "unitCode", null),
      property(local!address, "cityName", null),
      property(local!address, "zipCode", null)
    },
    ","
  )