<?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: pull data function returning 400 Invalid URL in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/pull-data-function-returning-400-invalid-url/m-p/1327130#M51632</link>
    <description>&lt;P&gt;Good news, it's working. Bad news, I'm not sure what exactly happened.&lt;/P&gt;&lt;P&gt;What I think happened is that there is some sort of disconnect between the code in the script window and the js file in the scripts folder. What I ended up doing was l tried to launch the script in an editor and then made changes. It just seemed to flip a switch or something and then the survey worked as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Sep 2023 01:39:10 GMT</pubDate>
    <dc:creator>MichaelKohler</dc:creator>
    <dc:date>2023-09-11T01:39:10Z</dc:date>
    <item>
      <title>pull data function returning 400 Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/pull-data-function-returning-400-invalid-url/m-p/1327113#M51631</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been using the Damage Assessment Solutions that includes Survey123 Connect XLS forms. Part of that is the JavaScript functions that should pull data from a feature service and use the data to populate a field in the survey. I keep getting a 400 error saying the URL is invalid. I've even created a URL that I know works and short circuited the JavaScript code and still get the invalid URL error. I've had this working in other surveys, just not the damage assessment.&lt;/P&gt;&lt;P&gt;This is how the function is called from the XLS&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;pulldata("@javascript","myJSFunctions.js","queryPolygon",string(${location}),"PARCELID",pulldata("@property","token"),true)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the code in the scripts folder.&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 queryPolygon(location,fields,token,debugmode){

    if (location===""){
        return (debugmode? "Location Object is empty":"");
    }

    var featureLayer = "https://services1.arcgis.com/**********/arcgis/rest/services/RE_PARCELS_WEB/FeatureServer/0";

    var coordsArray = location.split(" ");
    var coords = coordsArray[1] + "," + coordsArray[0]

    var xmlhttp = new XMLHttpRequest();
    var url = featureLayer + "/query?geometry=" + coords + "&amp;amp;geometryType=esriGeometryPoint&amp;amp;inSR=4326&amp;amp;spatialRel=esriSpatialRelIntersects&amp;amp;outFields=" + fields + "&amp;amp;returnGeometry=false&amp;amp;returnCount=1&amp;amp;f=json"


    if (token){
        url = url + "&amp;amp;token=" + token;
    }

    xmlhttp.open("GET",url,false);
        xmlhttp.send();

    if (xmlhttp.status!==200){
        return (debugmode? xmlhttp.status:"");
    } else {
        var responseJSON=JSON.parse(xmlhttp.responseText)
        if (responseJSON.error){
            return (debugmode? JSON.stringify(responseJSON.error):"");
        } else {
            if (responseJSON.features[0]){
                return JSON.stringify(responseJSON.features[0]);
            }
            else{
                return (debugmode? "No Features Found":"");
            }
        }
    }
}&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;This is the error that is stored in the JSON field. See Picture&lt;/P&gt;&lt;P&gt;{"code":400,"message":"Invalid URL","details":["Invalid URL"]}&lt;/P&gt;&lt;P&gt;Then I created a url that I know works and hardcoded it into the code and still get the same error.&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 queryPolygon(location,fields,token,debugmode){
    if (location===""){
        return (debugmode? "Location Object is empty":"");
    }
    var featureLayer = "https://services1.arcgis.com/***********/arcgis/rest/services/RE_PARCELS_WEB/FeatureServer/0";
    var coordsArray = location.split(" ");
    var coords = coordsArray[1] + "," + coordsArray[0]
    var xmlhttp = new XMLHttpRequest();
    var url = featureLayer + "/query?geometry=" + coords + "&amp;amp;geometryType=esriGeometryPoint&amp;amp;inSR=4326&amp;amp;spatialRel=esriSpatialRelIntersects&amp;amp;outFields=" + fields + "&amp;amp;returnGeometry=false&amp;amp;returnCount=1&amp;amp;f=json"

    //short circut url with known url that works when pasted into browser.
    var url = "https://services1.arcgis.com/**********/arcgis/rest/services/RE_PARCELS_WEB/FeatureServer/0/query?geometry=-80.39273,27.21473&amp;amp;geometryType=esriGeometryPoint&amp;amp;inSR=4326&amp;amp;spatialRel=esriSpatialRelIntersects&amp;amp;outFields=PARCELID&amp;amp;returnGeometry=false&amp;amp;returnCount=1&amp;amp;f=json"

    if (token){
        url = url + "&amp;amp;token=" + token;
    }

    xmlhttp.open("GET",url,false);
        xmlhttp.send();

    if (xmlhttp.status!==200){
        return (debugmode? xmlhttp.status:"");
    } else {
        var responseJSON=JSON.parse(xmlhttp.responseText)
        if (responseJSON.error){
            return (debugmode? JSON.stringify(responseJSON.error):"");
        } else {
            if (responseJSON.features[0]){
                return JSON.stringify(responseJSON.features[0]);
            }
            else{
                return (debugmode? "No Features Found":"");
            }
        }
    }
}&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;Any ideas would be greatly appreciated. As well on what the debug mode is and how would someone debug this code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2023 14:57:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/pull-data-function-returning-400-invalid-url/m-p/1327113#M51631</guid>
      <dc:creator>MichaelKohler</dc:creator>
      <dc:date>2023-09-10T14:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: pull data function returning 400 Invalid URL</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/pull-data-function-returning-400-invalid-url/m-p/1327130#M51632</link>
      <description>&lt;P&gt;Good news, it's working. Bad news, I'm not sure what exactly happened.&lt;/P&gt;&lt;P&gt;What I think happened is that there is some sort of disconnect between the code in the script window and the js file in the scripts folder. What I ended up doing was l tried to launch the script in an editor and then made changes. It just seemed to flip a switch or something and then the survey worked as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 01:39:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/pull-data-function-returning-400-invalid-url/m-p/1327130#M51632</guid>
      <dc:creator>MichaelKohler</dc:creator>
      <dc:date>2023-09-11T01:39:10Z</dc:date>
    </item>
  </channel>
</rss>

