Skip to main content
vikashk739
Inspiring
Jul 29, 2022 5:32 AM UTC
Solved

Expression rule to format address

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)
        )
        )

harshitb6843
Brainy
Jul 29, 2022 5:46 AM UTC

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
Brainy
Jul 29, 2022 5:46 AM UTC

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
Inspiring
Jul 29, 2022 6:29 AM UTC

Hi Harshit, the Joinarray function worked

Inspiring
Jul 29, 2022 5:47 AM UTC

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)
  },
  ", "
)

Inspiring
Jul 29, 2022 5:51 AM UTC

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)
    },
    ","
  )