Reference error when using SelectFeatures

473
4
Jump to solution
03-15-2018 07:35 AM
Helenpeng
New Contributor III

My widget code runs well with the correct result. But I see the reference error in Console Window – it says countyFeatureLayer is not defined.

My widget is to show the query result in Attribute table. I use two queries – the first query is to check if the drawbox-polygon is inside the state boundary. The second query is to intersect with countyFeatureLayer to get the county attribute info. Reading questions in the forum, I use SelectFeatures and show the query result in attribute table.

I define countyFeatureLayer in postCreate. In _onDrawComplete function, I just countyFeatureLayer.selectFeatures. My code does not have the error before using SelectFeatures.  Also, I checked my reference, which is same as my sandbox code. I do not know why I get the reference error. See the screenshot.

I also attach my widget zip files.

Thanks,

Helen

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Helen,

   So on this line you are missing the "this." portion:

console.log("countyFeatureLayer " + countyFeatureLayer.name);

it should be:

console.log("countyFeatureLayer " + this.countyFeatureLayer.name);

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Helen,

   I can't tell you much without seeing your code but it sounds like a scope issue where the countyFeatureLayer var is not available in the scope of the function you are trying to use it in.

0 Kudos
Helenpeng
New Contributor III

Robert,

I add var countyFeatureLayer; But it can not remove the undefined error.  I do not need to define var in my Sandbox code , which runs well with no error.

Though the error does not impact my result, I can receive correct results. But I would like to fix the error. I wonder if you have any suggestions. 

My widget code (zipped) is attached in the previous message. 

Thanks,

Helen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   So on this line you are missing the "this." portion:

console.log("countyFeatureLayer " + countyFeatureLayer.name);

it should be:

console.log("countyFeatureLayer " + this.countyFeatureLayer.name);
Helenpeng
New Contributor III

Robert,

Yes, this is the problem. Thank you for solving my issue. I thought it was some reference or variable problems, never check console.log.

I am kind of new to custom-widget. The forum is very helpful. By reading questions in the forum, I found the way to show query results in attribute table by using SelectFeatures. Much appreciated!

Best,

Helen

0 Kudos