So after asking Robert Scheitlin, GISP about some custom URL parameters I've been able to tweak some code modifications he sent to extrapolate upon them. But I'm hitting a weird error. Here is my code:
//now check if there is a url search to do var myObject = this.getUrlParams(); if (myObject.esearch) { if(myObject.esearch === "curmonth"){ var today = new Date(); today.setDate(1); var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd'); myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd'); console.info(myObject.esearch); } if(myObject.esearch === "curyear"){ var today = new Date(); today.setDate(1); var thisYearStr = this._formatDate(today.getTime(), 'yyyy'); console.info("This year string is : " + thisYearStr); myObject.esearch = this._formatDate(new Date(thisYearStr), 'yyyy'); console.info("This year string AFTER modiication is : " + myObject.esearch); } if(this.config.layers[myObject.slayer].expressions.expression.length > 0){ var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value); var values = myObject.esearch.split("|"); array.forEach(values, lang.hitch(this, function(val, index){ if (val.indexOf('~') > -1){ var ranges = val.split("~"); valuesObj1[index].valueObj.value1 = ranges[0]; valuesObj1[index].valueObj.value2 = ranges[1]; }else{ valuesObj1[index].valueObj.value = val; } })); html.empty(this.textsearchlabel); html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel); this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url, this.config.layers[myObject.slayer].definitionexpression); this.selectLayerAttribute.set('value', myObject.slayer); on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () { this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false); })); }
What's happening is on line 11 when it finds curyear, the variable 'thisYearStr' loads FINE... but the 'myObject.esearch' converts it to 2015.
Any ideas?
Solved! Go to Solution.
Got it!
On line 16 you don't need the "new Date" but just "Date" and it works. I hadn't modified the code well enough.
//now check if there is a url search to do var myObject = this.getUrlParams(); if (myObject.esearch) { if(myObject.esearch === "curmonth"){ var today = new Date(); today.setDate(1); var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd'); myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd'); console.info(myObject.esearch); } if(myObject.esearch === "curyear"){ var today = new Date(); today.setDate(1); var thisYearStr = this._formatDate(today.getTime(), 'yyyy'); myObject.esearch = this._formatDate(Date(thisYearStr), 'yyyy'); console.info(myObject.esearch); } if(this.config.layers[myObject.slayer].expressions.expression.length > 0){ var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value); var values = myObject.esearch.split("|"); array.forEach(values, lang.hitch(this, function(val, index){ if (val.indexOf('~') > -1){ var ranges = val.split("~"); valuesObj1[index].valueObj.value1 = ranges[0]; valuesObj1[index].valueObj.value2 = ranges[1]; }else{ valuesObj1[index].valueObj.value = val; } })); html.empty(this.textsearchlabel); html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel); this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url, this.config.layers[myObject.slayer].definitionexpression); this.selectLayerAttribute.set('value', myObject.slayer); on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () { this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false); })); }
Voila!
Got it!
On line 16 you don't need the "new Date" but just "Date" and it works. I hadn't modified the code well enough.
//now check if there is a url search to do var myObject = this.getUrlParams(); if (myObject.esearch) { if(myObject.esearch === "curmonth"){ var today = new Date(); today.setDate(1); var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd'); myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd'); console.info(myObject.esearch); } if(myObject.esearch === "curyear"){ var today = new Date(); today.setDate(1); var thisYearStr = this._formatDate(today.getTime(), 'yyyy'); myObject.esearch = this._formatDate(Date(thisYearStr), 'yyyy'); console.info(myObject.esearch); } if(this.config.layers[myObject.slayer].expressions.expression.length > 0){ var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value); var values = myObject.esearch.split("|"); array.forEach(values, lang.hitch(this, function(val, index){ if (val.indexOf('~') > -1){ var ranges = val.split("~"); valuesObj1[index].valueObj.value1 = ranges[0]; valuesObj1[index].valueObj.value2 = ranges[1]; }else{ valuesObj1[index].valueObj.value = val; } })); html.empty(this.textsearchlabel); html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel); this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url, this.config.layers[myObject.slayer].definitionexpression); this.selectLayerAttribute.set('value', myObject.slayer); on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () { this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false); })); }
Voila!