Arcade function not labeling correctly

1015
5
Jump to solution
09-13-2017 09:39 AM
roemhildtg
Occasional Contributor III

So, I'm trying to make a list of items in a label. Should look like this:

Instead, its looking like this:

The arcade snippet:

function bullet(item, isLast){
    return ' - ' + item + IIF(isLast, '', '\n');
}

function list(items){
    var body = '';
    for(var item in items){
        var index = IndexOf(items, item);
        var isLast = index == Count(items) - 1;
        body += IIF(IsEmpty(item), '', bullet(item, isLast));
    }
    
    return body;
}


'<BOL>UND>' + 'test' + '</BOL></UND>\n' + list( ['hey', 'there'])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

What would be the issue I'm missing?

0 Kudos
1 Solution

Accepted Solutions
roemhildtg
Occasional Contributor III

This is the correction of the typo I had in my function. for(var i in items) i is actually the index, not the item.

function bullet(item, isLast){
    return ' - ' + item + IIF(isLast, '', '\n');
}

function list(items){
    var body = '';
    for(var index in items){
        var isLast = index == Count(items) - 1;
        body += IIF(IsEmpty(item), '', bullet(items[index], isLast));
    }
    
    return body;
}

View solution in original post

0 Kudos
5 Replies
Greg_Mattis
Occasional Contributor II

Is the list going to be drawing from a field or is it just going to be text in the arcade expression?

Greg Mattis, GISP
GIS Analyst
City of Visalia
0 Kudos
roemhildtg
Occasional Contributor III

I'm going to be passing it a field. So something like this:

'<BOL>UND>' + $feature.field1 + '</BOL></UND>\n' + list( [$feature.field2, $feature.field3])
0 Kudos
Greg_Mattis
Occasional Contributor II

I was able to get it to work without the list function. To my knowledge I do not think that Arcade supports list functions. I wasn't able to find it in the ArcGIS Arcade documentation.

Here Arcade expression I was able to get to work with putting the values of the "list" on separate lines.

"<BOL>"+"<UND>"+$feature.field1+"</UND>"+"</BOL>" + TextFormatting.Newline + $feature.field2 + TextFormatting.Newline + $feature.field3

Let me know if you have any questions

Greg Mattis, GISP
GIS Analyst
City of Visalia
0 Kudos
roemhildtg
Occasional Contributor III

gmattis_visalia wrote:

I was able to get it to work without the list function. To my knowledge I do not think that Arcade supports list functions. I wasn't able to find it in the ArcGIS Arcade documentation.

I think you may have missed part of the code. I have a function "list" defined above. It does a little bit of processing to see if the field has a value, and adds a bullet point to the field so its in a list-like format, like in the screenshot. The idea is, some fields may be empty or null, and I don't want them to have an empty bullet point, I'd rather they are skipped.

0 Kudos
roemhildtg
Occasional Contributor III

This is the correction of the typo I had in my function. for(var i in items) i is actually the index, not the item.

function bullet(item, isLast){
    return ' - ' + item + IIF(isLast, '', '\n');
}

function list(items){
    var body = '';
    for(var index in items){
        var isLast = index == Count(items) - 1;
        body += IIF(IsEmpty(item), '', bullet(items[index], isLast));
    }
    
    return body;
}
0 Kudos