<?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 JS function works in web form but returns error in mobile app in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1418917#M56687</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Can anyone tell me why a javascript function I'm using in one of my surveys works great in the web form but gives me a type error when I submit in the mobile app? Any advice would be much appreciated. Lots of details below.&lt;/P&gt;&lt;P&gt;I'm not great with javascript so my function is probably clunky. It is intended to take the responses from a select multiple question, remove "Other" (if it's in there), sort the rest alphabetically, and return it. It works in survey123 connect and the webform.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function sortString(inputString){
	let anArray = inputString.split(",");
	let len = anArray.length;
	let other = -1;

	if (inputString.includes('Other')){
		other = anArray.indexOf('Other');
		delete anArray[other];
		anArray = anArray.sort().splice(0,len-1);
	}
	else{anArray=anArray.sort();}

	return anArray.join(',');
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This screenshot shows the result if I submit using the web form (works as expected) and the result if I submit using the mobile app (the type error)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KellyTaylor_0-1714763501246.png" style="width: 601px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103052iB2B9B4E0B2B2D6CA/image-dimensions/601x53?v=v2" width="601" height="53" role="button" title="KellyTaylor_0-1714763501246.png" alt="KellyTaylor_0-1714763501246.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an abbreviated version of what my xlsform looks like with only the relevant questions and fields shown.&lt;/P&gt;&lt;P&gt;The idea here is that the user selects from a list in "cleanup_null1". Those selections then get sorted alphabetically (minus "Other" if they selected it) in "cleanup_sorted". Then they enter more information in "cleanup_other1" if they selected "Other". The final result is in "request_cleanup_type" where it either stores the "cleanup_sorted" or a concatenation of "cleanup_sorted" and "cleanup_other1"&lt;/P&gt;&lt;P&gt;The only response that is sent to the source layer is "request_cleanup_type", and the only fields visible to the user are "cleanup_null1" and, if they select "Other" then "cleanup_other1"&lt;/P&gt;&lt;TABLE width="948"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;type&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;label&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;calculation&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;relevant&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;bind::esri:fieldType&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;select_multiple cleanup_type&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;cleanup_null1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;Request Cleanup Type&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;text&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;cleanup_sorted&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;sorted&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;pulldata("@javascript", "functions.js", "sortString", ${cleanup_null1})&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;text&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;cleanup_other1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;Request Cleanup Type: Other&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;selected(${cleanup_null1}, 'Other')&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;text&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;request_cleanup_type&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;Requested Cleanup&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;if(selected(${cleanup_null1},'Other'), concat( ${cleanup_sorted},',',${cleanup_other1}), ${cleanup_sorted})&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2024 19:55:38 GMT</pubDate>
    <dc:creator>KellyTaylor</dc:creator>
    <dc:date>2024-05-03T19:55:38Z</dc:date>
    <item>
      <title>JS function works in web form but returns error in mobile app</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1418917#M56687</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Can anyone tell me why a javascript function I'm using in one of my surveys works great in the web form but gives me a type error when I submit in the mobile app? Any advice would be much appreciated. Lots of details below.&lt;/P&gt;&lt;P&gt;I'm not great with javascript so my function is probably clunky. It is intended to take the responses from a select multiple question, remove "Other" (if it's in there), sort the rest alphabetically, and return it. It works in survey123 connect and the webform.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function sortString(inputString){
	let anArray = inputString.split(",");
	let len = anArray.length;
	let other = -1;

	if (inputString.includes('Other')){
		other = anArray.indexOf('Other');
		delete anArray[other];
		anArray = anArray.sort().splice(0,len-1);
	}
	else{anArray=anArray.sort();}

	return anArray.join(',');
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This screenshot shows the result if I submit using the web form (works as expected) and the result if I submit using the mobile app (the type error)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KellyTaylor_0-1714763501246.png" style="width: 601px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103052iB2B9B4E0B2B2D6CA/image-dimensions/601x53?v=v2" width="601" height="53" role="button" title="KellyTaylor_0-1714763501246.png" alt="KellyTaylor_0-1714763501246.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an abbreviated version of what my xlsform looks like with only the relevant questions and fields shown.&lt;/P&gt;&lt;P&gt;The idea here is that the user selects from a list in "cleanup_null1". Those selections then get sorted alphabetically (minus "Other" if they selected it) in "cleanup_sorted". Then they enter more information in "cleanup_other1" if they selected "Other". The final result is in "request_cleanup_type" where it either stores the "cleanup_sorted" or a concatenation of "cleanup_sorted" and "cleanup_other1"&lt;/P&gt;&lt;P&gt;The only response that is sent to the source layer is "request_cleanup_type", and the only fields visible to the user are "cleanup_null1" and, if they select "Other" then "cleanup_other1"&lt;/P&gt;&lt;TABLE width="948"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;type&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;label&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;calculation&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;relevant&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;bind::esri:fieldType&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;select_multiple cleanup_type&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;cleanup_null1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;Request Cleanup Type&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;text&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;cleanup_sorted&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;sorted&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;pulldata("@javascript", "functions.js", "sortString", ${cleanup_null1})&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;text&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;cleanup_other1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;Request Cleanup Type: Other&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&lt;P&gt;selected(${cleanup_null1}, 'Other')&lt;/P&gt;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;null&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="120.111px"&gt;&lt;P&gt;text&lt;/P&gt;&lt;/TD&gt;&lt;TD width="171.556px"&gt;&lt;P&gt;request_cleanup_type&lt;/P&gt;&lt;/TD&gt;&lt;TD width="89.1528px"&gt;&lt;P&gt;Requested Cleanup&lt;/P&gt;&lt;/TD&gt;&lt;TD width="297.792px"&gt;&lt;P&gt;if(selected(${cleanup_null1},'Other'), concat( ${cleanup_sorted},',',${cleanup_other1}), ${cleanup_sorted})&lt;/P&gt;&lt;/TD&gt;&lt;TD width="201.083px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="153.764px"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 19:55:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1418917#M56687</guid>
      <dc:creator>KellyTaylor</dc:creator>
      <dc:date>2024-05-03T19:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: JS function works in web form but returns error in mobile app</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1418961#M56691</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/43349"&gt;@KellyTaylor&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;The field app is passing the select_multiple values in as an array so the split() method is throwing the error. Try:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function sortString(input){&lt;BR /&gt;    let inputString = input.toString();&lt;BR /&gt;    let anArray = inputString.split(",");&lt;BR /&gt;    let len = anArray.length;&lt;BR /&gt;    let other = -1;&lt;BR /&gt;&lt;BR /&gt;    if (inputString.includes('Other')){&lt;BR /&gt;        other = anArray.indexOf('Other');&lt;BR /&gt;        delete anArray[other];&lt;BR /&gt;        anArray = anArray.sort().splice(0,len-1);&lt;BR /&gt;    }&lt;BR /&gt;    else{anArray=anArray.sort();}&lt;BR /&gt;    return anArray.join(',');&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2024 23:01:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1418961#M56691</guid>
      <dc:creator>ZacharySutherby</dc:creator>
      <dc:date>2024-05-03T23:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: JS function works in web form but returns error in mobile app</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1419296#M56696</link>
      <description>&lt;P&gt;Thanks so much, that did the trick!&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 13:45:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/js-function-works-in-web-form-but-returns-error-in/m-p/1419296#M56696</guid>
      <dc:creator>KellyTaylor</dc:creator>
      <dc:date>2024-05-06T13:45:58Z</dc:date>
    </item>
  </channel>
</rss>

