Select to view content in your preferred language

Definition Expression Fails When Using <> Operator

758
4
Jump to solution
02-17-2023 11:10 AM
MichaelCollinsGIS
New Contributor II

Hi All:

I want to be able to programmaticaly apply a "<>" operator to a definition expression. Nothing complicated, just something like layer.definitionExpression = "Status <> 'Closed'" because I don't want to include an OR clause in the query.

The error that I get is "'where' parameter is invalid" however if I try to apply the same query to the REST endpoint it returns the data fine. I tried encoding the string manually and also using encodeURIComponent, but neither worked.

Anyone have any idea what I am doing wrong?

Best,

MTC

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Yeah, that's definitely incorrect. I should have tested it first. However, using "<>" in a definitionExpression works when added to this sample.

const featureLayer = new FeatureLayer({
  url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
});
map.add(featureLayer);      
featureLayer.definitionExpression = "Cmn_Name <> 'White oak'";

 Can you provide more code to replicate the problem?

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

Use "!=" instead of "<>"

0 Kudos
MichaelCollinsGIS
New Contributor II

Unfortunately, I tried that too. No avail.

MichaelCollinsGIS_0-1676661777929.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Yeah, that's definitely incorrect. I should have tested it first. However, using "<>" in a definitionExpression works when added to this sample.

const featureLayer = new FeatureLayer({
  url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
});
map.add(featureLayer);      
featureLayer.definitionExpression = "Cmn_Name <> 'White oak'";

 Can you provide more code to replicate the problem?

MichaelCollinsGIS
New Contributor II

It's funny how a simple question can shake something important loose:

this.apply = function () {
    console.log(self.queryEditor.innerHTML); // prints "Status &lt;&gt; 'Open'"
    featureLayer.definitionExpression = self.queryEditor.innerHTML;
    featureTable.refresh();
};

Now obviously, changing that from innerHTML to innerText yields:

this.apply = function () {
    console.log(self.queryEditor.innerText); // prints "Status <> 'Open'"
    featureLayer.definitionExpression = self.queryEditor.innerText;
    featureTable.refresh();
};

And this works as expected.

Thanks for the nudge.

0 Kudos