Select to view content in your preferred language

Data Expression

926
7
10-18-2022 09:49 AM
Hammers211
Regular Contributor

Hello! I am attempting to use data expressions as described in this page, however I am getting an error:

Hammers21_0-1666111654610.png

 

I'm trying to use the first example, and have copy/pasted the text and replaced the survey URL and item ID. Can anyone help me figure out what this error means and why I am getting it?

Thank you!

0 Kudos
7 Replies
DougBrowning
MVP Esteemed Contributor

It usually means you are getting a null value in code then trying to access properties of it.  I have found that often the map must have at least 1 feature in it or arcade flips out and you cannot save it.

I think you forgot to post the actual code.  I have been doing a lot of data expressions so post the code and maybe I can see it.

0 Kudos
Hammers211
Regular Contributor

// Reference layer using the FeatureSetByPortalItem() function.
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '9cf4c3f33ac44231a36030dde78afb9b' , 0, ['list_name'], false);

 

I'm just doing it bit by bit at the moment, so above is all there is so far. FYI, I actually named it list_name.

0 Kudos
DougBrowning
MVP Esteemed Contributor

I looked up the service id and that is for the form.  You need to use the ID of the Feature Service where the data gets put.  123 always makes both.

Hammers211
Regular Contributor

Where do I find the ID for the Feature Service?

0 Kudos
DougBrowning
MVP Esteemed Contributor

Look in AGOL in the same folder as the form and you will see it.  Open the page then its right at the top in the URL.

0 Kudos
JohannesLindner
MVP Frequent Contributor

For reference, this is the expression:

// Reference layer using the FeatureSetByPortalItem() function. 
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'd10b9e8dbd7f4cccbd0a938a06c586e9' , 0, ['Report_road_condition'], false);

// Empty dictionary to capture each hazard reported as separate rows. 
var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}], 
                    'geometryType': '', 'features': []}; 

var index = 0; 

// Split comma separated hazard types and store in dictionary.  
for (var feature in fs) { 
    var split_array  =  Split(feature["Report_road_condition"], ',') 
    var count_arr = Count(split_array) 
    for(var i = 0; i < count_arr; i++ ){ 
        choicesDict.features[index++] = { 
            'attributes': { 'split_choices': Trim(split_array[i]),  
            }} 
}} 

// Convert dictionary to featureSet. 
var fs_dict = FeatureSet(Text(choicesDict)); 

// Return featureset after grouping by hazard types. 
return GroupBy(fs_dict, ['split_choices'], 
       [{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]); 

 

At a quick glance, I don't see where this error could come from. Anything I can think of would either work or give a different error. Check these points anyway:

  • Make sure your portal url and item and sublayer id are correct
  • Make sure you query the correct field (Report_road_condition in the example)
  • Make sure that this field is a text field

 

If these don't work, we need to know more to help:

  • Test the original expression from the example in your Dashboard, does that work?
  • Post your expression
  • If possible, share your data publicly

Have a great day!
Johannes
0 Kudos
Hammers211
Regular Contributor

Thank you for the suggestions, I will try them ASAP. Where do I find the item/sublayer IDs? Also, by "Make sure that this field is a text field" do you mean that the question type should be text? I need to use select multiple for this particular task. Hopefully I misunderstood.

0 Kudos