How do you get a date query to work?

10137
16
10-09-2014 07:40 AM
AndrewWolff1
New Contributor II

I have a date field in my hosted feature service that is being collected through the collector app.  I'm trying to build a query in the Web AppBuilder that selects records from a specific day however the query fails when the input is a date..  If I query date is blank or not blank it works fine.   Has anyone been able to create successful query based on date?

16 Replies
ErikLanhammar
Esri Contributor

Hello,

Im also having troubles with date in query widget. Im using WAB developer edition 1.3 and Im querying a date field in data exposed by a FS. It all works fine..

BUT - The date in the query widget UI is defaulting to the date I CONFIGURED the widget i WAB which is highly irrelevant..

How do I change this behaviour of the date picker to default to TODAYS DATE (whenever I run a query)?!

Thanks,

/Erik

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Erik,

  This would require changing code in the stemApp or just your specific app if you only need this change for that one app.

Open

[install dir]\client\stemapp\jimu.js\dijit\_SingleFilterParameter.js

or

[install dir]\server\apps\[app#]\jimu.js\dijit\_SingleFilterParameter.js

And find this line:

this.dateTextBox.set('value', new Date(valueObj.value));

and change it to:

this.dateTextBox.set('value', new Date());

ErikLanhammar
Esri Contributor

Thanks Robert, you made my day!!!

Brgds,

/Erik

0 Kudos
ErikLanhammar
Esri Contributor

Hello again Robert!

Thansk again for the fix - it works great in WAB13. I cant make it work in WAB11 though. Looked up the code in _SingelFilter.js, line 812 and changed

this.dateTextBox.set('value', new Date(valueObj.value));

to

this.dateTextBox.set('value', new Date());

...but date in query widget still defaults to the config date, not todays...

Any suggestion on how I can make it work in WAB11?

BRgds,

/Erik

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Erik,

  In 1.1 you need to change the _buildDate function in the SingleParameter.js file (line 24 & 25):

_buildDate: function(fieldInfo, part){
        /*jshint unused: false*/
        html.setStyle(this.stringTextBoxContainer,'display','none');
        html.setStyle(this.numberTextBoxContainer,'display','none');
        html.setStyle(this.dateTextBoxContainer,'display','block');

        var fieldObj = part.fieldObj;//name,shortType
        var valueObj = part.valueObj;//value,value1,value2
        var operator = part.operator;
        var isDateBetween = operator === this.OPERATORS.dateOperatorIsBetween;
        var isDateNotBetween = operator === this.OPERATORS.dateOperatorIsNotBetween;
        var isRange = isDateBetween || isDateNotBetween;
        if(isRange){
          this._type = 2;
          html.setStyle(this.dateRangeTable,'display','table');
          this._hideDijit(this.dateTextBox);
          this.dateTextBox1.set('value', new Date(valueObj.value1));
          this.dateTextBox2.set('value', new Date(valueObj.value2));
        }
        else{
          this._type = 1;
          html.setStyle(this.dateRangeTable,'display','none');
          this._showDijit(this.dateTextBox);
          //this.dateTextBox.set('value', new Date(valueObj.value));
          this.dateTextBox.set('value', new Date());
        }
      },
0 Kudos
ErikLanhammar
Esri Contributor

Thanks Robert, will try this!

Have a nice day,

/Erik

25 jan. 2016 kl. 17:36 skrev Robert Scheitlin, GISP <geonet@esri.com<mailto:geonet@esri.com>>:

GeoNet <https://community.esri.com/?et=watches.email.thread>

How do you get a date query to work?

reply from Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.thread> in Web AppBuilder for ArcGIS - View the full discussion<https://community.esri.com/message/582916?et=watches.email.thread#582916>

0 Kudos
AdamGebhart
Occasional Contributor III

Robert Scheitlin, GISP‌ - do you know in what file to make this update in 2.3?  I'm either not seeing the files you mentioned above or don't see those lines of code within the same files.  I'm sure the structure has changed since 1.1 and 1.2. 

To clarify, what I'm trying to set up is the second date below is always the present or previous day.   

0 Kudos