<?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 JavaScript function works in Connect but fails in Browser in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635027#M63454</link>
    <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;I have a JavaScript function that calculates date fields.&lt;BR /&gt;In my form i have the following configurations to make it work:&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;calculation: pulldata("@javascript", "calcularFechaVenc.js", "calcularFechaVenc", ${fecha_not_insc_concesion},700, ${periodo_de_trabajo})

relevant: string-length(${fecha_not_insc_concesion}) &amp;gt; 0 and (${periodo_de_trabajo} = 'plena_temp' or ${periodo_de_trabajo} = 'semi_temp' or ${periodo_de_trabajo} = 'todo_el_anio')&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The thing is, when i test this in the Survey123 Connect app. The target fields populate correctly, but when i do the exact same workflow in the browser, the fields doesnt fill. No error appears in console.&lt;BR /&gt;&lt;BR /&gt;I'm using Connect 3.22&lt;BR /&gt;&lt;BR /&gt;Any advice would really help me. Fell free to ask for more info&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jul 2025 17:27:49 GMT</pubDate>
    <dc:creator>JuanTomásMartinez17</dc:creator>
    <dc:date>2025-07-22T17:27:49Z</dc:date>
    <item>
      <title>JavaScript function works in Connect but fails in Browser</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635027#M63454</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;I have a JavaScript function that calculates date fields.&lt;BR /&gt;In my form i have the following configurations to make it work:&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;calculation: pulldata("@javascript", "calcularFechaVenc.js", "calcularFechaVenc", ${fecha_not_insc_concesion},700, ${periodo_de_trabajo})

relevant: string-length(${fecha_not_insc_concesion}) &amp;gt; 0 and (${periodo_de_trabajo} = 'plena_temp' or ${periodo_de_trabajo} = 'semi_temp' or ${periodo_de_trabajo} = 'todo_el_anio')&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The thing is, when i test this in the Survey123 Connect app. The target fields populate correctly, but when i do the exact same workflow in the browser, the fields doesnt fill. No error appears in console.&lt;BR /&gt;&lt;BR /&gt;I'm using Connect 3.22&lt;BR /&gt;&lt;BR /&gt;Any advice would really help me. Fell free to ask for more info&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 17:27:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635027#M63454</guid>
      <dc:creator>JuanTomásMartinez17</dc:creator>
      <dc:date>2025-07-22T17:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: JavaScript function works in Connect but fails in Browser</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635093#M63455</link>
      <description>&lt;P&gt;A couple thoughts:&lt;/P&gt;&lt;P&gt;Are you logged in when testing on the webapp, Javascript functions don't work for public surveys.&lt;/P&gt;&lt;P&gt;Sometimes JS functions triggers upon load and don't recalculate when new data is added.&amp;nbsp; I see you have a relevancy but have you tried calculationMode = always on that field.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-survey123-questions/text-field-populated-using-javascript-calculation/m-p/1615311" target="_blank"&gt;https://community.esri.com/t5/arcgis-survey123-questions/text-field-populated-using-javascript-calculation/m-p/1615311&lt;/A&gt;&lt;/P&gt;&lt;P&gt;How are you calculating the dates, is it possible to do outside a JS functions?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 17:43:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635093#M63455</guid>
      <dc:creator>Neal_t_k</dc:creator>
      <dc:date>2025-07-22T17:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: JavaScript function works in Connect but fails in Browser</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635097#M63456</link>
      <description>&lt;LI-CODE lang="javascript"&gt;function calcularFechaVenc(fechaInicio, cantidadDias, periodo) {
    let fecha = new Date(fechaInicio);
    let diasContados = 0;

    while (diasContados &amp;lt; cantidadDias) {
        let mes = fecha.getMonth();
        let esValido = true;

        if (periodo === 'plena_temp' &amp;amp;&amp;amp; mes &amp;gt;= 5 &amp;amp;&amp;amp; mes &amp;lt;= 9) {
            esValido = false;
        } else if (periodo === 'semi_temp' &amp;amp;&amp;amp; (mes === 6 || mes === 7)) {
            esValido = false;
        }

        if (esValido) {
            diasContados++;
        }

        if (diasContados &amp;lt; cantidadDias) {
            fecha.setDate(fecha.getDate() + 1);
        }
    }

    return fecha.toISOString().split("T")[0];

}&lt;/LI-CODE&gt;&lt;P&gt;This is how I’m calculating the dates. I’ve already explored all other possibilities — this workflow can only be achieved using JavaScript. Since the target fields are set to read-only, they remain invisible until the relevant condition is met. When that condition becomes true, the fields appear, but they show up blank (displaying DD-MM-YYYY, --:--).&lt;BR /&gt;&lt;BR /&gt;If the issue is that the JavaScript function only triggers on load, what would be the recommended solution?&lt;BR /&gt;&lt;BR /&gt;UPDATE: Setting the fields to &lt;EM&gt;read-only = no&lt;/EM&gt; did the trick. The only issue now is that I have to click the “Recalculate” button that appears below the question for the values to populate&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 18:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635097#M63456</guid>
      <dc:creator>JuanTomásMartinez17</dc:creator>
      <dc:date>2025-07-22T18:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: JavaScript function works in Connect but fails in Browser</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635106#M63458</link>
      <description>&lt;P&gt;Did you try "&lt;SPAN&gt;calculationMode = always" in the&amp;nbsp;&lt;EM&gt;bind::esri:parameters column?&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;&lt;A href="https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-calculation-modes/ba-p/1206967" target="_blank"&gt;https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-calculation-modes/ba-p/1206967&lt;/A&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 18:11:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635106#M63458</guid>
      <dc:creator>Neal_t_k</dc:creator>
      <dc:date>2025-07-22T18:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: JavaScript function works in Connect but fails in Browser</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635109#M63460</link>
      <description>&lt;P&gt;I tried, but as long as read-only is set to yes, the problem persists. To resolve the recalculation issue, I had to remove the relevant expression. Now I need to find a way to keep that field protected while still allowing the recalculation to work.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 18:25:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/javascript-function-works-in-connect-but-fails-in/m-p/1635109#M63460</guid>
      <dc:creator>JuanTomásMartinez17</dc:creator>
      <dc:date>2025-07-22T18:25:21Z</dc:date>
    </item>
  </channel>
</rss>

