<?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: Changing Data source of map to hosted feature service doesn't change ItemID in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035602#M6329</link>
    <description>&lt;P&gt;It turns out that the ItemID is stored in the layer's underlying Cartographic Information Model (CIM).&amp;nbsp; More specifically the ItemID value is stored &lt;SPAN&gt;in the SourceURI property of&lt;/SPAN&gt;&amp;nbsp;the&amp;nbsp;&lt;SPAN&gt;CIMFeatureLayer class.&amp;nbsp; The&amp;nbsp; SourceURI property is only populated when the layer is first added to a map, but the property is not updated when the data connection is changed.&amp;nbsp; To update the SourceURI you can use the following pattern (from within QueuedTask.Run):&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var dcLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault();
QueuedTask.Run(() =&amp;gt;
{
  if (!(dcLyr.GetDataConnection() is CIMStandardDataConnection dc))
  {
    MessageBox.Show("Layer doesn't have CIMStandardDataConnection");
    return;
  }
  // make changes to the data connection
  dcLyr.SetDataConnection(dc);
  // update SourceURI
  var lyrDef = dcLyr.GetDefinition();
  lyrDef.SourceURI = string.Empty;
  dcLyr.SetDefinition(lyrDef);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;In the snippet above the SourceURI is cleared, but it can also be replaced with the ItemID matching the new data connection.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 18:52:49 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2021-03-11T18:52:49Z</dc:date>
    <item>
      <title>Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1033238#M6307</link>
      <description>&lt;P&gt;I've created an Add-In to ArcGIS Pro to facilitate importing and publishing a web map. I have a map package that I'm importing. I need to change the data source in the map to a hosted feature service in ArcGIS Online. In the Add-In code, I have this method:&lt;/P&gt;&lt;P&gt;private static void ResetFeatureServiceDataConnection(Layer dataConnectionLayer, string newConnectionString)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CIMStandardDataConnection dataConnection = dataConnectionLayer.GetDataConnection() as CIMStandardDataConnection;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataConnection.WorkspaceConnectionString = newConnectionString;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataConnectionLayer.SetDataConnection(dataConnection);&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;The parameters to this method are a map layer and the URL for the hosted feature service. This method changes the data source in the layer, but it doesn't change the ItemID.The ItemID is referencing the original data source (from the map package I imported). When I publish the map, the datasource is based on the ItemID, not the Url that I've set in the code.&lt;/P&gt;&lt;P&gt;I've tried changing the data source from the Layer Properties in ArcGIS Pro. When I click the Set Data Source button and select the layer in my hosted feature service, the URL changes, but not the ItemID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to change the Item ID to match the ItemID of the hosted feature service?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 01:43:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1033238#M6307</guid>
      <dc:creator>ChrisSeabrooke1</dc:creator>
      <dc:date>2021-03-05T01:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1034757#M6320</link>
      <description>&lt;P&gt;I have a web map with two feature layers.&amp;nbsp; &amp;nbsp;The first layer in my Map references the first feature layer of my web map.&amp;nbsp; &amp;nbsp;Below is the code for a button's 'OnClick' method, that changes the data connection for this first layer from a feature service ID of '0' to '1' and vice versa.&amp;nbsp; Not sure if this is what you need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override void OnClick()
{
  try
  {
    var dcLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault();
    if (dcLyr == null)
    {
      MessageBox.Show("No Layer found");
      return;
    }
    QueuedTask.Run(() =&amp;gt;
    {
      CIMStandardDataConnection dc = dcLyr.GetDataConnection() as CIMStandardDataConnection;
      if (dc == null)
      {
        MessageBox.Show("Layer doesn't have CIMStandardDataConnection");
        return;
      }
      if (dc.Dataset == "0") 
        dc.Dataset = "1";
      else
        dc.Dataset = "0";
      dcLyr.SetDataConnection(dc);
    });
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.Message);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 23:59:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1034757#M6320</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-03-09T23:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1034762#M6321</link>
      <description>&lt;P&gt;Thanks for the reply but&amp;nbsp; I'm trying to change the ItemID for every layer in the map to the correct hosted feature service. &lt;SPAN&gt;I can change the URL, but I need to change the ItemID to the hosted feature service.&amp;nbsp;The datasource is based on the ItemID, not the URL.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 00:11:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1034762#M6321</guid>
      <dc:creator>ChrisSeabrooke1</dc:creator>
      <dc:date>2021-03-10T00:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035074#M6324</link>
      <description>&lt;P&gt;To change the URL to the hosted feature service you have to change the Url, to change the ID you have to change the Dataset property as shown in the sample below.&amp;nbsp; When you say you have to change the '&lt;SPAN&gt;ItemID' to the hosted feature service do you mean the ID?&amp;nbsp; As shown here:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wolf_0-1615403733293.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8107iBB22123F81278A7E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Wolf_0-1615403733293.png" alt="Wolf_0-1615403733293.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If so then, my sample applies to your question. in the sample I change this (note that the ID is shown under the &lt;STRONG&gt;Name&lt;/STRONG&gt; line item):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="After.png" style="width: 744px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8105iC578C78F568500B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="After.png" alt="After.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;To this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Before.png" style="width: 780px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8106iEC25E471155BA370/image-size/large?v=v2&amp;amp;px=999" role="button" title="Before.png" alt="Before.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In this sample snippet the datasource for the layer is changed from FeatureSerive to MapService and vice versa, and in addition the ID is also changed from '0' to '2' and vice versa.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override void OnClick()
{
	try
	{
		var dcLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault();
		if (dcLyr == null)
		{
			MessageBox.Show("No Layer found");
			return;
		}
		QueuedTask.Run(() =&amp;gt;
		{
			if (!(dcLyr.GetDataConnection() is CIMStandardDataConnection dc))
			{
				MessageBox.Show("Layer doesn't have CIMStandardDataConnection");
				return;
			}
			if (dc.WorkspaceConnectionString.Contains(@"/FeatureServer"))
				dc.WorkspaceConnectionString = dc.WorkspaceConnectionString.Replace(@"/FeatureServer", @"/MapServer");
			else
				dc.WorkspaceConnectionString = dc.WorkspaceConnectionString.Replace(@"/MapServer", @"/FeatureServer");
			if (dc.Dataset == "0")
				dc.Dataset = "2";
			else
				dc.Dataset = "0";
			dcLyr.SetDataConnection(dc);
		});
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message);
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 19:15:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035074#M6324</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-03-10T19:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035094#M6325</link>
      <description>&lt;P&gt;I am not trying to change the ID of the layer. I am trying to change the itemId -- which is the reference to the hosted feature service. I've changed the data source as you've indicated above, but that does not change the itemId. Using ArcGIS Online Assistant, I can see the ItemID is "330dbdc986f34ebd884b42171ff165ae". This is not the ID for the feature service 'SeabrookeFieldSeeker' as you can see from the second image.&amp;nbsp; This is causing the map layers to reference a hosted feature service that is not the one in the URL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChrisSeabrooke1_0-1615404369463.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8108i7AD6E8AAE091C597/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChrisSeabrooke1_0-1615404369463.png" alt="ChrisSeabrooke1_0-1615404369463.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChrisSeabrooke1_1-1615404519954.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8109i8F29E550243B24BB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChrisSeabrooke1_1-1615404519954.png" alt="ChrisSeabrooke1_1-1615404519954.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 19:38:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035094#M6325</guid>
      <dc:creator>ChrisSeabrooke1</dc:creator>
      <dc:date>2021-03-10T19:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035118#M6326</link>
      <description>&lt;P&gt;My bad, I guess I overlooked the 'ArcGIS Online' part.&amp;nbsp; The actual 'Feature Service' is hosted on ArcGIS Server referenced the the "url" attribute of the "operationallayer" json from your previous reply.&amp;nbsp; I only looked at the ArcGIS Server datassource, not a Portal (ArcGIS Online) connection.&amp;nbsp; I will try a Portal datasource now and let you know what i find.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 19:56:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035118#M6326</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-03-10T19:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035602#M6329</link>
      <description>&lt;P&gt;It turns out that the ItemID is stored in the layer's underlying Cartographic Information Model (CIM).&amp;nbsp; More specifically the ItemID value is stored &lt;SPAN&gt;in the SourceURI property of&lt;/SPAN&gt;&amp;nbsp;the&amp;nbsp;&lt;SPAN&gt;CIMFeatureLayer class.&amp;nbsp; The&amp;nbsp; SourceURI property is only populated when the layer is first added to a map, but the property is not updated when the data connection is changed.&amp;nbsp; To update the SourceURI you can use the following pattern (from within QueuedTask.Run):&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var dcLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault();
QueuedTask.Run(() =&amp;gt;
{
  if (!(dcLyr.GetDataConnection() is CIMStandardDataConnection dc))
  {
    MessageBox.Show("Layer doesn't have CIMStandardDataConnection");
    return;
  }
  // make changes to the data connection
  dcLyr.SetDataConnection(dc);
  // update SourceURI
  var lyrDef = dcLyr.GetDefinition();
  lyrDef.SourceURI = string.Empty;
  dcLyr.SetDefinition(lyrDef);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;In the snippet above the SourceURI is cleared, but it can also be replaced with the ItemID matching the new data connection.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 18:52:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035602#M6329</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-03-11T18:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Data source of map to hosted feature service doesn't change ItemID</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035789#M6330</link>
      <description>&lt;P&gt;Wolf, thank you. That was exactly what I needed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 01:56:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/changing-data-source-of-map-to-hosted-feature/m-p/1035789#M6330</guid>
      <dc:creator>ChrisSeabrooke1</dc:creator>
      <dc:date>2021-03-12T01:56:37Z</dc:date>
    </item>
  </channel>
</rss>

