Label expression If Else multiple fields

762
2
Jump to solution
02-07-2023 12:44 AM
NicolasSoenens
New Contributor II

I have 4 Attributes  in One label.

I have 4 attributes in 1 label.
Each attribute starts with a title and then the text.

If the text = null for an attribute I would not want to see a title for this attribute.

Do I have to write a completely new script for each attribute?

NicolasSoenens_0-1675759310741.png

 

"ZEE-"&"<BOL><CLR red='21' green='47' blue='255'>" & [Km_paal_in_zee] &  "</CLR></BOL>"& vbNewLine &

" OP-"&"<BOL><CLR red='21' green='47' blue='255'>"& [Oriëntatiepaal]&  "</CLR></BOL>"& vbNewLine &

"Vast-"&"<BOL><CLR red='21' green='47' blue='255'>" &[vaste_plaatsnaam]&  "</CLR></BOL>"& vbNewLine &

"Lok-"&"<BOL><CLR red='21' green='47' blue='255'>" &[Lokale_benaming]&  "</CLR></BOL>"

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Switch tha language to Arcade, use this expression:

var titles = ["ZEE", "OP", "Vast", "Lok"]
var values = [
    $feature.Km_paal_in_zee,
    $feature.Oriëntatiepaal,
    $feature.vaste_plaatsnaam,
    $feature.Lokale_benaming,
    ]

var lines = []
for(var i in titles) {
    if(!IsEmpty(values[i])) {
        var line = `${titles[i]}-<BOL><CLR red="21" green="47" blue="255">${values[i]}</CLR></BOL>`
        Push(lines, line)
    }
}
return Concatenate(lines, TextFormatting.NewLine)

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

Switch tha language to Arcade, use this expression:

var titles = ["ZEE", "OP", "Vast", "Lok"]
var values = [
    $feature.Km_paal_in_zee,
    $feature.Oriëntatiepaal,
    $feature.vaste_plaatsnaam,
    $feature.Lokale_benaming,
    ]

var lines = []
for(var i in titles) {
    if(!IsEmpty(values[i])) {
        var line = `${titles[i]}-<BOL><CLR red="21" green="47" blue="255">${values[i]}</CLR></BOL>`
        Push(lines, line)
    }
}
return Concatenate(lines, TextFormatting.NewLine)

Have a great day!
Johannes
NicolasSoenens
New Contributor II

🙂 

You made my day!

Thanks

NicolasSoenens_0-1675761755910.png

 

 

0 Kudos