<?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: 4.16 FeatureLayer bug when using relative URL for service in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1065281#M73400</link>
    <description>&lt;P&gt;Although there's no mention of it in the release notes, this has been fixed in 4.19.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jun 2021 19:25:03 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2021-06-04T19:25:03Z</dc:date>
    <item>
      <title>4.16 FeatureLayer bug when using relative URL for service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/41118#M3512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When creating an instance of a FeatureLayer, I've run across a bug that occurs when passing a relative URL for the service. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;FeatureLayer&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;url&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"/arcgis/rest/services/someFolder/someService/MapServer/0"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The layer loads its service properties ok, but when querying the service for features, it includes the layer ID in the URL twice:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;A href="https://hostname/arcgis/rest/services/someFolder/someService/MapServer" target="_blank"&gt;https://hostname/arcgis/rest/services/someFolder/someService/MapServer&lt;/A&gt;&lt;SPAN style="color: #ff0000;"&gt;/0/0&lt;/SPAN&gt;/query?f=json&amp;amp;etc=etc&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Needless to say, the queries fail to execute. When initializing the FeatureLayer object, the logic "thinks" it parses the URL into a path and layerID. For example, if you pass an absolute URL, the following properties will be set:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//sample URL = &lt;SPAN style="color: #0000ff;"&gt;&lt;A href="https://hostname/arcgis/rest/services/someFolder/someService/MapServer/0" target="_blank"&gt;https://hostname/arcgis/rest/services/someFolder/someService/MapServer/0&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;url: &lt;A href="https://hostname/arcgis/rest/services/someFolder/someService/MapServer" target="_blank"&gt;https://hostname/arcgis/rest/services/someFolder/someService/MapServer&lt;/A&gt;&lt;BR /&gt;layerId: 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if you pass the relative URL:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//sample URL = &lt;SPAN style="color: #0000ff;"&gt;/arcgis/rest/services/someFolder/someService/MapServer/0&lt;/SPAN&gt;&lt;BR /&gt;url: /arcgis/rest/services/someFolder/someService/MapServer&lt;SPAN style="color: #ff0000;"&gt;/0&lt;/SPAN&gt;&lt;BR /&gt;layerId: &lt;SPAN style="color: #ff0000;"&gt;undefined&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After the layer's service info gets loaded, the state becomes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;url: /arcgis/rest/services/someFolder/someService/MapServer/0&lt;BR /&gt;layerId: &lt;SPAN style="color: #ff0000;"&gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Queries to the service join the url and layerId properties, thus you get:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt; /arcgis/rest/services/someFolder/someService/MapServer&lt;SPAN style="color: #ff0000;"&gt;/0/0&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem can be tracked down to the &lt;SPAN style="color: #ff00ff;"&gt;parse&lt;/SPAN&gt; function of the &lt;SPAN style="color: #ff00ff;"&gt;esri/layers/support/arcgisLayerUrl&lt;/SPAN&gt; module, which uses regular expressions to parse the service URL into various components.&amp;nbsp; This works fine for absolute URLs, but fails to work with relative URLs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One possible workaround is to convert all your URLs to absolute. However, this can be a problem if different users access the same server with different host names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Should you be using a locally hosted copy of the API,&amp;nbsp;a more robust workaround would be to fix the aforementioned parse method...in this case, directly in the init.js file. The first two statements of that function are as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;c&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;urlToObject&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; b&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;match&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;g&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;||&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;match&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've inserted the following code between those lines to convert relative URLs to absolute prior to being tested against the regular expressions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;indexOf&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"http"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;!==&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;indexOf&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"/"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;===&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
       &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;indexOf&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;"&lt;SPAN class="comment token"&gt;//") === 0)&lt;/SPAN&gt;
          c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; window&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;location&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;protocol &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
       &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;
          c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; window&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;location&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;protocol &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; "&lt;SPAN class="comment token"&gt;//" + window.location.hostname + c.path;&lt;/SPAN&gt;
    &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;indexOf&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;===&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
       c&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; window&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;location&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;protocol &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; "&lt;SPAN class="comment token"&gt;//" + window.location.hostname + window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/")) + c.path;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I've minified it when updating the init.js file. So basically, in init.js, you would search for:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;c=a.urlToObject(c);var b=c.path.match(g)||c.path.match(f);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and replace it with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000;"&gt;c=a.urlToObject(c);if(c.path.indexOf("http")!==0){if(c.path.indexOf("/")===0){if(c.path.indexOf("//")===0)c.path=window.location.protocol+c.path;else c.path=window.location.protocol+"//"+window.location.hostname+c.path;}else if(c.path.indexOf(".")===0)c.path=window.location.protocol+"//"+window.location.hostname+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+c.path;}var b=c.path.match(g)||c.path.match(f);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;As an aside, relative URLs worked fine in 3.x, and the 4.x documentation doesn't specify that absolute URLs are required.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This solution is specific to 4.16 and may not work in other versions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This post is for the benefit of those like me who experience this problem, and need a solution *now*.&amp;nbsp; I will not respond to requests to submit this to ESRI support.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/41118#M3512</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-12-10T21:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: 4.16 FeatureLayer bug when using relative URL for service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1045857#M72451</link>
      <description>&lt;P&gt;Experiencing this bug in 4.12 as well.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 10:03:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1045857#M72451</guid>
      <dc:creator>fabianmue</dc:creator>
      <dc:date>2021-04-12T10:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: 4.16 FeatureLayer bug when using relative URL for service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1049319#M72652</link>
      <description>&lt;P&gt;Here's a simplified solution for 4.18.&amp;nbsp; In init.js, search for:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;p=b.urlToObject(p);p=p.path.match(k)||p.path.match(r);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...and replace with:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;p=b.urlToObject(b.makeAbsolute(p));p=p.path.match(k)||p.path.match(r);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 19:27:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1049319#M72652</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-04-20T19:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: 4.16 FeatureLayer bug when using relative URL for service</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1065281#M73400</link>
      <description>&lt;P&gt;Although there's no mention of it in the release notes, this has been fixed in 4.19.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 19:25:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/4-16-featurelayer-bug-when-using-relative-url-for/m-p/1065281#M73400</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-06-04T19:25:03Z</dc:date>
    </item>
  </channel>
</rss>

