Select to view content in your preferred language

Arcade Text() function not formatting dates in popup on Field Maps

115
2
Jump to solution
a week ago
NigelCharman
Occasional Contributor

I have an Arcade expression on my popup which returns fields.

If the field type is an esriFieldTypeDate, we format the field as 'ddd DD MMM YYYY'. Opening the map in a browser the date displays correctly, e.g. 'Tue 19 Nov 2024'. However on Field Maps it's displaying as a long timestamp, e.g. '1731991427000'.

Is this a bug or am I doing something wrong?

 

Relevant Arcade code follows:

// Format field value based on type
function formatField(meta, fieldValue) {
if (meta.domain && meta.fieldType != 'esriFieldTypeInteger') {
return DomainName($feature, meta.name);
}
if (meta.fieldType == "esriFieldTypeDate") {
return Text(fieldValue, 'ddd DD MMM YYYY');
}
return fieldValue;
}


// Build final arrays in validFields order
var attributes = {};
var fieldInfos = [];


for (var v in validFields) {
var fieldName = validFields[v];
var fieldValue = $feature[fieldName];
 
if (!IsEmpty(fieldValue) && !IsNaN(fieldValue)) {
var meta = fieldMeta[fieldName];
var alias = meta.alias;
 
attributes[alias] = formatField(meta, fieldValue);
Push(fieldInfos, { fieldName: alias });
}
}


return {
type: "fields",
fieldInfos: fieldInfos,
attributes: attributes
};
0 Kudos
1 Solution

Accepted Solutions
NigelCharman
Occasional Contributor

Thanks for your answer @ChristopherCounsell.

It turned out to be much more obscure. I'd omitted to give you the preceding code, which I'd created from @PaulBarker's article Introducing Arcade pop-up content elements:

// Get field metadata
var fieldMeta = {};
for (var f in fields) {
    var fieldName = fields[f].name;
    if (HasKey(validFieldsSet, fieldName)) {
        fieldMeta[fieldName] = {
            alias: fields[f].alias,
            domain: HasKey(fields[f], "domain"),
            fieldType: fields[f].type,
            name: fieldName
        };
    }
}

The problem is that HasKey(fields[f], "domain") returns true on Field Maps, but false on Web Maps.

I've solved it by changing this line to also check for an empty domain value:

            domain: HasKey(fields[f], "domain") && !IsEmpty(fields[f].domain),

and the date fields now display as desired.

Any chance someone at ESRI could update the Introducing Arcade pop-up content elements article with this solution so others don't get the same problem?

View solution in original post

2 Replies
ChristopherCounsell
MVP Regular Contributor

It's your return statement casting it as type:fields.

Field maps is returning the text() back as the the field type, which is date, so it converts the text(date) back to epoch time.

You could try forcing the function to return it as a text e.g.

return Text(fieldValue, 'ddd DD MMM YYYY') + "";

Or update the final return statement to return text, as html or something like this:

return {
type: "text",
text: attributes[alias]
};

0 Kudos
NigelCharman
Occasional Contributor

Thanks for your answer @ChristopherCounsell.

It turned out to be much more obscure. I'd omitted to give you the preceding code, which I'd created from @PaulBarker's article Introducing Arcade pop-up content elements:

// Get field metadata
var fieldMeta = {};
for (var f in fields) {
    var fieldName = fields[f].name;
    if (HasKey(validFieldsSet, fieldName)) {
        fieldMeta[fieldName] = {
            alias: fields[f].alias,
            domain: HasKey(fields[f], "domain"),
            fieldType: fields[f].type,
            name: fieldName
        };
    }
}

The problem is that HasKey(fields[f], "domain") returns true on Field Maps, but false on Web Maps.

I've solved it by changing this line to also check for an empty domain value:

            domain: HasKey(fields[f], "domain") && !IsEmpty(fields[f].domain),

and the date fields now display as desired.

Any chance someone at ESRI could update the Introducing Arcade pop-up content elements article with this solution so others don't get the same problem?