<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic eSearch Custom Code : curyear in Web AppBuilder Custom Widgets Questions</title>
    <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/esearch-custom-code-curyear/m-p/877176#M13686</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So after asking &lt;A href="https://community.esri.com/migrated-users/3101" target="_blank"&gt;Robert Scheitlin, GISP&lt;/A&gt;​ 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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//now check if there is a url search to do
var myObject = this.getUrlParams();
if (myObject.esearch) {
&amp;nbsp; if(myObject.esearch === "curmonth"){
&amp;nbsp; var today = new Date();
&amp;nbsp; today.setDate(1);
&amp;nbsp; var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd');
&amp;nbsp; myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd');
&amp;nbsp; console.info(myObject.esearch);
&amp;nbsp; }
&amp;nbsp; if(myObject.esearch === "curyear"){
&amp;nbsp; var today = new Date();
&amp;nbsp; today.setDate(1);
&amp;nbsp; var thisYearStr = this._formatDate(today.getTime(), 'yyyy');
&amp;nbsp; console.info("This year string is : " + thisYearStr);
&amp;nbsp; myObject.esearch = this._formatDate(new Date(thisYearStr), 'yyyy');
&amp;nbsp; console.info("This year string AFTER modiication is : " + myObject.esearch);
&amp;nbsp; }
&amp;nbsp; if(this.config.layers[myObject.slayer].expressions.expression.length &amp;gt; 0){
&amp;nbsp; var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value);
&amp;nbsp; var values = myObject.esearch.split("|");
&amp;nbsp; array.forEach(values, lang.hitch(this, function(val, index){
&amp;nbsp;&amp;nbsp; if (val.indexOf('~') &amp;gt; -1){
&amp;nbsp; var ranges = val.split("~");
&amp;nbsp; valuesObj1[index].valueObj.value1 = ranges[0];
&amp;nbsp; valuesObj1[index].valueObj.value2 = ranges[1];
&amp;nbsp;&amp;nbsp; }else{
&amp;nbsp; valuesObj1[index].valueObj.value = val;
&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }));
&amp;nbsp; html.empty(this.textsearchlabel);
&amp;nbsp; html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel);
&amp;nbsp; this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url,
&amp;nbsp; this.config.layers[myObject.slayer].definitionexpression);
&amp;nbsp; this.selectLayerAttribute.set('value', myObject.slayer);
&amp;nbsp; on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () {
&amp;nbsp;&amp;nbsp; this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false);
&amp;nbsp; }));
&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What's happening is on line 11 when it finds curyear, the variable 'thisYearStr' loads FINE... but the 'myObject.esearch' converts it to 2015.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 11:00:54 GMT</pubDate>
    <dc:creator>BrianO_keefe</dc:creator>
    <dc:date>2021-12-12T11:00:54Z</dc:date>
    <item>
      <title>eSearch Custom Code : curyear</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/esearch-custom-code-curyear/m-p/877176#M13686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So after asking &lt;A href="https://community.esri.com/migrated-users/3101" target="_blank"&gt;Robert Scheitlin, GISP&lt;/A&gt;​ 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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//now check if there is a url search to do
var myObject = this.getUrlParams();
if (myObject.esearch) {
&amp;nbsp; if(myObject.esearch === "curmonth"){
&amp;nbsp; var today = new Date();
&amp;nbsp; today.setDate(1);
&amp;nbsp; var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd');
&amp;nbsp; myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd');
&amp;nbsp; console.info(myObject.esearch);
&amp;nbsp; }
&amp;nbsp; if(myObject.esearch === "curyear"){
&amp;nbsp; var today = new Date();
&amp;nbsp; today.setDate(1);
&amp;nbsp; var thisYearStr = this._formatDate(today.getTime(), 'yyyy');
&amp;nbsp; console.info("This year string is : " + thisYearStr);
&amp;nbsp; myObject.esearch = this._formatDate(new Date(thisYearStr), 'yyyy');
&amp;nbsp; console.info("This year string AFTER modiication is : " + myObject.esearch);
&amp;nbsp; }
&amp;nbsp; if(this.config.layers[myObject.slayer].expressions.expression.length &amp;gt; 0){
&amp;nbsp; var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value);
&amp;nbsp; var values = myObject.esearch.split("|");
&amp;nbsp; array.forEach(values, lang.hitch(this, function(val, index){
&amp;nbsp;&amp;nbsp; if (val.indexOf('~') &amp;gt; -1){
&amp;nbsp; var ranges = val.split("~");
&amp;nbsp; valuesObj1[index].valueObj.value1 = ranges[0];
&amp;nbsp; valuesObj1[index].valueObj.value2 = ranges[1];
&amp;nbsp;&amp;nbsp; }else{
&amp;nbsp; valuesObj1[index].valueObj.value = val;
&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }));
&amp;nbsp; html.empty(this.textsearchlabel);
&amp;nbsp; html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel);
&amp;nbsp; this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url,
&amp;nbsp; this.config.layers[myObject.slayer].definitionexpression);
&amp;nbsp; this.selectLayerAttribute.set('value', myObject.slayer);
&amp;nbsp; on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () {
&amp;nbsp;&amp;nbsp; this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false);
&amp;nbsp; }));
&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What's happening is on line 11 when it finds curyear, the variable 'thisYearStr' loads FINE... but the 'myObject.esearch' converts it to 2015.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 11:00:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/esearch-custom-code-curyear/m-p/877176#M13686</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2021-12-12T11:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: eSearch Custom Code : curyear</title>
      <link>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/esearch-custom-code-curyear/m-p/877177#M13687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got it!&lt;/P&gt;&lt;P&gt;On line 16 you don't need the "new Date" but just "Date" and it works. I hadn't modified the code well enough.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//now check if there is a url search to do
var myObject = this.getUrlParams();
if (myObject.esearch) {
&amp;nbsp; if(myObject.esearch === "curmonth"){
&amp;nbsp; var today = new Date();
&amp;nbsp; today.setDate(1);
&amp;nbsp; var thisMonthStr = this._formatDate(today.getTime(), 'yyyy/MM/dd');
&amp;nbsp; myObject.esearch = thisMonthStr + "~" + this._formatDate(new Date().getTime(), 'yyyy/MM/dd');
&amp;nbsp; console.info(myObject.esearch);
&amp;nbsp; }
&amp;nbsp; if(myObject.esearch === "curyear"){
&amp;nbsp; var today = new Date();
&amp;nbsp; today.setDate(1);
&amp;nbsp; var thisYearStr = this._formatDate(today.getTime(), 'yyyy');
&amp;nbsp; myObject.esearch = this._formatDate(Date(thisYearStr), 'yyyy');
&amp;nbsp; console.info(myObject.esearch);
&amp;nbsp; }
&amp;nbsp; if(this.config.layers[myObject.slayer].expressions.expression.length &amp;gt; 0){
&amp;nbsp; var valuesObj1 = lang.clone(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].values.value);
&amp;nbsp; var values = myObject.esearch.split("|");
&amp;nbsp; array.forEach(values, lang.hitch(this, function(val, index){
&amp;nbsp;&amp;nbsp; if (val.indexOf('~') &amp;gt; -1){
&amp;nbsp; var ranges = val.split("~");
&amp;nbsp; valuesObj1[index].valueObj.value1 = ranges[0];
&amp;nbsp; valuesObj1[index].valueObj.value2 = ranges[1];
&amp;nbsp;&amp;nbsp; }else{
&amp;nbsp; valuesObj1[index].valueObj.value = val;
&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }));
&amp;nbsp; html.empty(this.textsearchlabel);
&amp;nbsp; html.place(html.toDom(this.config.layers[myObject.slayer].expressions.expression[myObject.exprnum].textsearchlabel), this.textsearchlabel);
&amp;nbsp; this.paramsDijit.build(valuesObj1, this.resultLayers[myObject.slayer], this.config.layers[myObject.slayer].url,
&amp;nbsp; this.config.layers[myObject.slayer].definitionexpression);
&amp;nbsp; this.selectLayerAttribute.set('value', myObject.slayer);
&amp;nbsp; on.once(this.paramsDijit, 'param-ready', lang.hitch(this, function () {
&amp;nbsp;&amp;nbsp; this._queryFromURL(myObject.esearch, myObject.slayer, myObject.exprnum, myObject.close || false);
&amp;nbsp; }));
&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Voila!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 11:00:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/web-appbuilder-custom-widgets-questions/esearch-custom-code-curyear/m-p/877177#M13687</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2021-12-12T11:00:57Z</dc:date>
    </item>
  </channel>
</rss>

