Cannot set properties of undefined (setting 'OBJECTID')

133
2
Jump to solution
a month ago
cadgism
Occasional Contributor

Hi 

1. I am creating a new feature layer based on a spatial query. The query is fine. It selects the features  can see it in console.log

2. Created a new feature layer out of this queried results, also works perfect   can see the feature layer attributes in console too

3. When I am trying to add this layer to the map,  it produces an error  "Cannot set properties of undefined (setting 'OBJECTID')" and stops. Any help please

 

 

query.executeQueryJSON(searchUrl, queryObj).then(function (results) {
                    console.log(results.features.length);
                    //new feature layer to put selected features
                    selSketch = new FeatureLayer({ id: "selSketchLayer", outfields:"[*]" });
                    if (results.features.length > 999) {
                        alert("Max Record Count more than 1000. Please Select smaller area !!!");
                        deleteSketch();
                        return;
                    };
                    skfeatures = results.features;
                    var fields = results.fields;
                    selSketch.source = results.features;
                    selSketch.fields = fields;
                    selSketch.objectIdField = "OBJECTID";
                    selSketch.renderer = selSketchRenderer;
                    app.map.remove(Rerdlayer);
                    app.map.add(selSketch);

 

 

 

ErrorError

 

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

When creating a client-side FeatureLayer, you must set the layer's schema correctly in the layer constructor especially if the source is not set. You cannot just set fields schema to wild card. You need to set the fields schema. Since you are creating a new client-side feature layer from query results, try changing your code as shown below and see if it fixes the problem. 

 

 

const featureSet = results.features; 
const layer = new FeatureLayer({
   source: featureSet,
   geometryType: featureSet.geometryType,
   objectIdField: "OBJECTID",
   fields: featureSet.fields,
   renderer: selSketchRenderer,
   //spatialReference: results.features[0].geometry.spatialReference
});

 

 

 

View solution in original post

2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

When creating a client-side FeatureLayer, you must set the layer's schema correctly in the layer constructor especially if the source is not set. You cannot just set fields schema to wild card. You need to set the fields schema. Since you are creating a new client-side feature layer from query results, try changing your code as shown below and see if it fixes the problem. 

 

 

const featureSet = results.features; 
const layer = new FeatureLayer({
   source: featureSet,
   geometryType: featureSet.geometryType,
   objectIdField: "OBJECTID",
   fields: featureSet.fields,
   renderer: selSketchRenderer,
   //spatialReference: results.features[0].geometry.spatialReference
});

 

 

 

cadgism
Occasional Contributor

Thank you, It Works!!!

0 Kudos