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

  Discussion posts and replies are publicly visible

Parents
  • 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. 

Reply
  • 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. 

Children