FeatureLayer setDefinitionExpression & Internet Explorer

4216
10
Jump to solution
09-28-2015 01:30 PM
SteveCole
Frequent Contributor

This strikes me as odd but I guess it really shouldn't since this is Internet Explorer..

Anyways, I have a simple page that loads two feature layers that have two date fields (a beginning and ending date for events). When I add the layers to my map, I attempt to apply a defintion expression based on those date fields:

var today = new Date();
var theDefExp = "endDate > date '" + today.toLocaleDateString() + "'";
theLayer.setDefinitionExpression(theDefExp);

This works fine in Chrome and Firefox but, under Internet Explorer 11 (and using any "previous" document modes), this throws 400 errors when it actually attempts to display features. In the ArcGIS Server logs, here's the real error:

An invalid where clause or definition expression has been requested: "endDate > date '‎9‎/‎28‎/‎2015'"

So why does this cause heartburn for IE but not Chrome/Firefox? More importantly, what do I need to change to make it IE friendly?

Thanks!

Steve

0 Kudos
10 Replies
SteveCole
Frequent Contributor

Just got off the phone with ESRI after submitting a possible bug request about this. After a lengthy call, we finally determined that the issue was not with ESRI's software. The problem lies with my use of the Date.toLocaleDateString() function.

For whatever reason, the encoding must be different or something. The final solution was a little less elegant but it now works within IE:

    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    var theCurDate = month + "/" + day + "/" + year;
    
    var theDefExp = "endDate >= date '" + theCurDate + "'";
    theLayer.setDefinitionExpression(theDefExp);
0 Kudos