Arcade data expression: copy a single value from a feature set to all rows of a new one

1240
4
Jump to solution
09-21-2021 05:52 AM
Labels (1)
Merlin
by
New Contributor III

Hi there,

I appear to have lost my way in a seemingly easy task. I would like to copy a certain value (TestSeptember) from one feature set to a new one:

2021-09-21 14_36_52-Window.png

2021-09-21 14_38_04-Window.png

Edit: the FFG_Name is blank due to data privacy (contains names).

Anyone who could guide me through this?

Cheers,
Merlin 

If it helps, here my code so far:

Spoiler
var p = 'xxx';
var itemID = 'xxx';
var layerID = 0;

var mCSV = FeatureSetByPortalItem(Portal(p),itemID,layerID, ['*'], false );

var cuMoSt = Text(Date(Max(mCSV,'ModuleStart')),'YYYY-MM-DD');
var cuMoEn = Text(Date(Max(mCSV,'ModuleEnd')),'YYYY-MM-DD');
var cuMoDe = Filter (mCSV, 'ModuleStart >= @cuMoSt AND ModuleEnd <= @cuMoEn');

//return cuMoDe

var p = 'xxx';
var itemID = 'xxx';
var layerID = 0;

var att = FeatureSetByPortalItem(Portal(p),itemID,layerID,['start_time','end_time','FFG_Name','FT_Name','BA_Username','FT_att_men','FT_att_women','FT_att_all'],false );

var lastM = date(year(today()),month(today())-1,01);
var thisM = date(year(today()),month(today()),01);

var attCuMoFi = Filter (att, 'start_time >= @cuMoSt AND start_time <= @cuMoEn');

var dict = {
  fields: [
    { name: 'Module_desc',      type: 'esriFieldTypeString' },
    { name: 'start_time',       type: 'esriFieldTypeString' },
    { name: 'end_time',         type: 'esriFieldTypeString' },
    { name: 'FFG_Name',         type: 'esriFieldTypeString' },
    { name: 'FT_Name',          type: 'esriFieldTypeString' },
    { name: 'BA_Username',      type: 'esriFieldTypeString' },
    { name: 'FT_att_men',       type: 'esriFieldTypeString' },
    { name: 'FT_att_women',     type: 'esriFieldTypeString' },
    { name: 'FT_att_all',       type: 'esriFieldTypeString' },
  ],
  geometryType: '',
  features: [],
};

var index = 0;
for (var feature in attCuMoFi) { 
    dict.features[index] = { 
        'attributes': { 
            'start_time': Text(feature['start_time'],'YYYY-MM-DD'),
            'end_time': Text(feature['end_time'],'YYYY-MM-DD'),
            'FFG_Name': Text(feature['FFG_Name']),
            'FT_Name': Text(feature['FT_Name']),
            'BA_Username': Decode(Text(feature['BA_Username']),
			xxx
            'missing data'),
            'FT_att_men': Number(feature['FT_att_men']),
            'FT_att_women': Number(feature['FT_att_women']),
            'FT_att_all': Number(feature['FT_att_all']),
        }} 
    index++;
} 
var fs_dict = FeatureSet(Text(dict));
return fs_dict

 

---
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor
// before line 40
var module_desc = null
if(Count(cuMoDe) > 0) {
  module_desc = First(cuMoDe).ModuleDescription
}

// before line 44
'Module_desc': module_desc,

Have a great day!
Johannes

View solution in original post

4 Replies
DavidPike
MVP Frequent Contributor

looks fine (and very nicely formatted).  I'm wondering if it's as simple as FFG_Name being an alias? Also what's the original format of FFG_Name? What does it look like?
can you test it with 

return att

 

0 Kudos
Merlin
by
New Contributor III

Hi David,

The FFG_Name field was blank to hide the names that actually show up.

My goal is to copy the ModuleDescription Field containing the string 'TestSeptember' to all rows of the second fs.

This was ppl. misguiding in the original post. I tried to edit and clarify.

---
0 Kudos
JohannesLindner
MVP Frequent Contributor
// before line 40
var module_desc = null
if(Count(cuMoDe) > 0) {
  module_desc = First(cuMoDe).ModuleDescription
}

// before line 44
'Module_desc': module_desc,

Have a great day!
Johannes
Merlin
by
New Contributor III

Excellent! Cheers Johannes.

This was the function that did all I needed:

First(cuMoDe).ModuleDescription

 

---
0 Kudos