<?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: How to add query table to map in python in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772593#M790</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got it working with Python 3 here are the steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;create aprx file: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;aprx = arcpy.mp.ArcGISProject(&amp;lt;blank aprx file&amp;gt;)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;get the map object:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;m_map = aprx.listMaps()[0]&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;create a table object from the view:&amp;nbsp;&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table = arcpy.mp.Table(&amp;lt;path to db view&amp;gt;)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;name the table:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table.name = &amp;lt;name I make up&amp;gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;add a where clause: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table.definitionQuery = '&amp;lt;where clause&amp;gt;'&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;add the table to the map:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;m_map.addTable (table)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;save aprx file:&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;aprx.save()&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;publish the aprx&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This sequence is actually the same as the code I use to add regular tables (not views) to a map - so it should have been fairly obvious to me.&amp;nbsp; I think the real reason my code kept failing was that my view did not include an OBJECTID column - or perhaps more precisely a column with non-null unique values (at least that is what the documentation says is required of all tables and views). Once I added a non-null unique column column I was able to create and publish the map.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Feb 2020 12:37:25 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2020-02-26T12:37:25Z</dc:date>
    <item>
      <title>How to add query table to map in python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772591#M788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an SQL Server view that at I want to include in my ArcGIS server's REST endpoint as a table. I'm able to do it manually using ArcMap - it appears to create a query table when I drag the view onto the table of contents.&amp;nbsp;How can I do this in python?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently I go through this sequence&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Start with a blank mxd file:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;mxd_template_obj =&amp;nbsp;arcpy.mapping.MapDocument(blank_template_fn)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Get the dataframe: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;df = ListDataFrames(mxd_template_obj)[0]&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Create the query table (according to the documentation is creates a TableView):&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.MakeQueryTable_management(db_view, table_view_name, ....)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Convert it to a TableView object:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table_view =&amp;nbsp;arcpy.mapping.TableView(table_view_name)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Add it to the map:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.mapping.AddTableView(df, table_view)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Save the map: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;mxd_template_obj.saveACopy(&amp;lt;mxd_file_name&amp;gt;)&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears to generate a good mxd file - I can go into ArcMap and everything looks correct, but when I try to stage it for publishing I get this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ExecuteError: ERROR 001272: Analyzer errors were encountered (codes = 33, 33)&lt;/P&gt;&lt;P&gt;Standalone table's data source is not supported&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect that my step 4 is wrong - once I have the query table I need to do something else to get it into the map correctly but I'm not sure what that is.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2019 17:54:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772591#M788</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2019-09-17T17:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to add query table to map in python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772592#M789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got this to work on Python 2.7 by changing step 3 from MakeQueryTable to MakeQueryLayer. Now I'm trying to figure out how to do the equivalent in Python 3/ArcPro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL style="background-color: #ffffff; border: 0px; padding: 0px 0px 0px 30px;"&gt;&lt;LI style="border: 0px; font-weight: inherit; margin: 0.5ex 0px;"&gt;Start with a blank mxd file:&amp;nbsp;&lt;SPAN style="border: 0px; font-weight: inherit; font-family: 'courier new', courier, monospace;"&gt;mxd_template_obj =&amp;nbsp;arcpy.mapping.MapDocument(blank_template_fn)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI style="border: 0px; font-weight: inherit; margin: 0.5ex 0px;"&gt;Get the dataframe:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="border: 0px; font-weight: inherit; font-family: 'courier new', courier, monospace;"&gt;df = ListDataFrames(mxd_template_obj)[0]&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI style="border: 0px; font-weight: inherit; margin: 0.5ex 0px;"&gt;Create the query layer:&amp;nbsp;&lt;SPAN style="border: 0px; font-weight: inherit; font-family: 'courier new', courier, monospace;"&gt;arcpy.MakeQueryLayer_management(db_view, table_view_name, ....)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI style="border: 0px; font-weight: inherit; margin: 0.5ex 0px;"&gt;Convert it to a TableView object:&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;&lt;SPAN style="border: 0px; font-weight: inherit;"&gt;table_view =&amp;nbsp;arcpy.mapping.TableView(table_view_name)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI style="border: 0px; font-weight: inherit; margin: 0.5ex 0px;"&gt;Add it to the map:&amp;nbsp;&lt;SPAN style="border: 0px; font-weight: inherit; font-family: 'courier new', courier, monospace;"&gt;arcpy.mapping.AddTableView(df, table_view)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI style="border: 0px; font-weight: inherit; margin: 0.5ex 0px;"&gt;Save the map:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="border: 0px; font-weight: inherit; font-family: 'courier new', courier, monospace;"&gt;mxd_template_obj.saveACopy(&amp;lt;mxd_file_name&amp;gt;)&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Feb 2020 13:03:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772592#M789</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2020-02-25T13:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to add query table to map in python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772593#M790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got it working with Python 3 here are the steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;create aprx file: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;aprx = arcpy.mp.ArcGISProject(&amp;lt;blank aprx file&amp;gt;)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;get the map object:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;m_map = aprx.listMaps()[0]&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;create a table object from the view:&amp;nbsp;&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table = arcpy.mp.Table(&amp;lt;path to db view&amp;gt;)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;name the table:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table.name = &amp;lt;name I make up&amp;gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;add a where clause: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;table.definitionQuery = '&amp;lt;where clause&amp;gt;'&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;add the table to the map:&amp;nbsp;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;m_map.addTable (table)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;save aprx file:&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp;aprx.save()&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;publish the aprx&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This sequence is actually the same as the code I use to add regular tables (not views) to a map - so it should have been fairly obvious to me.&amp;nbsp; I think the real reason my code kept failing was that my view did not include an OBJECTID column - or perhaps more precisely a column with non-null unique values (at least that is what the documentation says is required of all tables and views). Once I added a non-null unique column column I was able to create and publish the map.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Feb 2020 12:37:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-add-query-table-to-map-in-python/m-p/772593#M790</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2020-02-26T12:37:25Z</dc:date>
    </item>
  </channel>
</rss>

