Date field returns empty in Arcade expression

580
2
Jump to solution
05-01-2023 09:45 AM
Labels (1)
GregKeith
Occasional Contributor III

I have a data expression for a dashboard indicator (below). The problem is that the 'created_date' field returns no values. I have seen the thread here, but can't see where I'm going wrong. The date does show up in the Console as either:

Script: attributes: {sample: po['sample_id_post_pfas'],created: Number(po['created_date'])}:
Console: {"attributes":{"sample":"123-A-456","created":1678124975146}}
Script: attributes: {sample: po['sample_id_post_pfas'],created: po['created_date']}:
Console: {"attributes":{"sample":"123-A-456","created":"2023-03-06T17:49:35.146Z"}}

 The basic idea is that there are 700+ records, each of which can have null or values in any of 7 id fields, although only checking 3 here. My goal is to get a count of all non-null ids, along with the date created (same date for all ids in a single record). If I have 700 records, for example, there might be 900 samples. I've got the count, but want to be able to filter by date in the dashboard.

Any idea what I'm missing? Thanks.

 

 

var p = Portal('gisportal')
var fs = FeatureSetByPortalItem(
    p,
    '6a8fd262c6e641c6bc9513da29fc3910',
    0,
    [
        'sample_id_dup',
        'sample_id_pre',
        'sample_id_post',
        'created_date'
     ],
    false
    );    
var dup = Filter(fs, 'sample_id_dup IS NOT NULL');    
var pre = Filter(fs, 'sample_id_pre IS NOT NULL');
var post = Filter(fs, 'sample_id_post IS NOT NULL');
var features = [];
var feat;
for (var d in dup) {
    feat = {
        attributes: {
            sample: d['sample_id_dup'],
            created: Number(d['created_date'])
        },
    };
    Push(features, feat);
};

for (var pr in pre) {
    feat = {
        attributes: {
            sample: pr['sample_id_pre'],
            created: Number(pr['created_date'])
        },
    };
    Push(features, feat);
};

for (var po in post) {
    feat = {
        attributes: {
            sample: po['sample_id_post'],
            created: Number(po['created_date'])
        },
    };
    Push(features, feat);
};

var joinedDict = {
    fields: [
            {name: 'sample', type: 'esriFieldTypeString'},
            {name: 'created_date', type: 'esriFieldTypeDate'}
    ],
    geometryType: '',
    features: features
}

return FeatureSet(Text(joinedDict));

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You named the field "created_date" (line 52), but in the features, you call it "created" (lines 23. 33, 34). They have to be the same.


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

You named the field "created_date" (line 52), but in the features, you call it "created" (lines 23. 33, 34). They have to be the same.


Have a great day!
Johannes
GregKeith
Occasional Contributor III

Thanks @JohannesLindner . Obvious in hindsight 🙃

0 Kudos