<?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 Re: Survey123 JavaScript calculation returns empty date field in web form but works in Connect in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638876#M63651</link>
    <description>&lt;P&gt;If I am reading you JS script correctly you could set up that logic directly in the form without the JS.&amp;nbsp; You would end up with a pretty complex if statement though.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Aug 2025 16:49:23 GMT</pubDate>
    <dc:creator>Neal_t_k</dc:creator>
    <dc:date>2025-08-04T16:49:23Z</dc:date>
    <item>
      <title>Survey123 JavaScript calculation returns empty date field in web form but works in Connect</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638760#M63646</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I'm working on a Survey123 form where I need to calculate the next due date for a semiannual payment (always due on June 30 or December 31). I’m using a JavaScript function via pulldata("@javascript") to do this, and it works perfectly in Survey123 Connect. However, in the web version, the field stays empty—even when I manually trigger recalculation.&lt;/P&gt;&lt;P&gt;Here’s what I’ve done:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;I have a date field called fecha_prox_venc whose value is calculated using the script below.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;The function takes two inputs:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;fecha_venc_canon: inside a repeat, refers to the last due date payed&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;fecha_inicio_canon: the initial date to start counting from, if no payment has been made&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The field that should populate with the output has the following calculation:&amp;nbsp;pulldata("@javascript", "vencCanon.js", "calcularProximoVencimiento", max(${fecha_venc_canon}), ${fecha_inicio_canon})&lt;/P&gt;&lt;P&gt;Here’s the JavaScript I'm using (vencCanon.js):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function calcularProximoVencimiento(ultima_fecha_venc, fecha_inicio_canon) {
  let base;

  if (ultima_fecha_venc) {
    base = new Date(ultima_fecha_venc);
  } else if (fecha_inicio_canon) {
    base = new Date(fecha_inicio_canon);
  } else {
    return null;
  }

  let dia = base.getDate();
  let mes = base.getMonth(); // 0-indexed
  let anio = base.getFullYear();
  let proximo;

  if (mes === 5 &amp;amp;&amp;amp; dia === 30) {
    proximo = new Date(anio, 11, 31);
  } else if (mes === 11 &amp;amp;&amp;amp; dia === 31) {
    proximo = new Date(anio + 1, 5, 30);
  } else {
    if (mes &amp;lt; 6) {
      proximo = new Date(anio, 5, 30);
    } else {
      proximo = new Date(anio, 11, 31);
    }
  }

  // Ajustar a las 3:00am para evitar desfasaje por zona horaria
  proximo.setHours(3, 0, 0, 0);

  // Formato completo con hora
  return proximo.toISOString();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 12:44:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638760#M63646</guid>
      <dc:creator>JuanTomásMartinez17</dc:creator>
      <dc:date>2025-08-04T12:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 JavaScript calculation returns empty date field in web form but works in Connect</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638765#M63647</link>
      <description>&lt;P&gt;This post is from 2020 but it does say at the bottom of the post.&lt;/P&gt;&lt;P&gt;Passing repeats or questions within a repeat to a JS function only works in Connect and the mobile app&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/ba-p/898782" target="_blank"&gt;https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/ba-p/898782&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That could be it.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 13:08:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638765#M63647</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2025-08-04T13:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 JavaScript calculation returns empty date field in web form but works in Connect</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638778#M63649</link>
      <description>&lt;P&gt;The&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/survey123/desktop/create-surveys/pulldatajavascript.htm#:~:text=feature%20layer.-,Repeats,-You%20can%20pass" target="_self"&gt;JavaScript functions in survey forms&lt;/A&gt;&amp;nbsp;Repeat section appears to support what Doug is saying.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A possible solution to explore is if you have access to ArcGIS for Power Automate or some other workflow automation tool you might be able to set it up to fill the due date in that field when a new survey is submitted.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 14:01:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638778#M63649</guid>
      <dc:creator>TylerGraham2</dc:creator>
      <dc:date>2025-08-04T14:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 JavaScript calculation returns empty date field in web form but works in Connect</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638876#M63651</link>
      <description>&lt;P&gt;If I am reading you JS script correctly you could set up that logic directly in the form without the JS.&amp;nbsp; You would end up with a pretty complex if statement though.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 16:49:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1638876#M63651</guid>
      <dc:creator>Neal_t_k</dc:creator>
      <dc:date>2025-08-04T16:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 JavaScript calculation returns empty date field in web form but works in Connect</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1639420#M63669</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/913499"&gt;@JuanTomásMartinez17&lt;/a&gt;&amp;nbsp;Try the attached out, should get you close to adjust as needed.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Aug 2025 20:48:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-calculation-returns-empty/m-p/1639420#M63669</guid>
      <dc:creator>Neal_t_k</dc:creator>
      <dc:date>2025-08-05T20:48:12Z</dc:date>
    </item>
  </channel>
</rss>

