<?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: GP tool for inserting a row into a standalone table? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248606#M64286</link>
    <description>&lt;P&gt;As Dan said, there's no out of the box tool. If you need that functionality in Model Builder, you have to create that tool yourself.&lt;/P&gt;&lt;P&gt;Below are two quick examples. You can save that script as a Python toolbox (.pyt), load that into ArcGIS Pro, and then drag the tools in to your model.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: cp1252 -*-

import arcpy


class Toolbox(object):
    def __init__(self):
        self.label = "Utility"
        self.alias = "utility"
        self.tools = [InsertRow, InsertRowIntoTableA]



class InsertRow(object):
    label="Insert Row"
    description="Inserts a row into a table"
    

    def getParameterInfo(self):
        parameters = [
            arcpy.Parameter(name="in_table", displayName="Table", datatype="DETable", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="row", displayName="Row", datatype="GPValueTable", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="out_table", displayName="Edited Table", datatype="DETable", parameterType="Derived", direction="Output"),
            ]
        parameters[1].columns = [
            ["GPString", "Field"],
            ["GPString", "Value"]
            ]
        return parameters
        

    def updateParameters(self, parameters):
        par = {p.name: p for p in parameters}
        
        in_table = str(par["in_table"].value)
        # reset fields if no table is selected
        if in_table == "None":
            par["row"].value = None
            return
        # get fields from the table
        target_fields = [
            f.name
            for f in arcpy.ListFields(in_table)
            if f.type not in ("OID", "GlobalID", "Geometry")
            ]
        # get currently loaded fields
        current_fields = []
        if par["row"].value is not None:
            current_fields = [
                f
                for f, v in par["row"].value
                ]
        # if these don't match, a different table was selected -&amp;gt; change fields
        if current_fields != target_fields:
            par["row"].value = [[f, None] for f in target_fields]


    def execute(self, parameters, messages):
        par = {p.name: p for p in parameters}
        # get fields with user input
        row = [
            [field, value]
            for field, value in par["row"].value
            if value not in ('', None)
            ]
        fields, values = list(zip(*row))
        # insert the new row
        # all values are str, but the InsertCursor should take care of the conversion
        with arcpy.da.InsertCursor(str(par["in_table"].value), fields) as cursor:
            cursor.insertRow(values)
        # set the output parameter
        par["out_table"].value = par["in_table"].value



class InsertRowIntoTableA(object):
    label="Insert Row into TableA"
    description="Inserts a row into TableA"
    

    def getParameterInfo(self):
        parameters = [
            arcpy.Parameter(name="in_table", displayName="TableA", datatype="DETable", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="ID_A", displayName="ID_A", datatype="GPLong", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="TEXT_A", displayName="TEXT_A", datatype="GPString", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="out_table", displayName="Edited TableA", datatype="DETable", parameterType="Derived", direction="Output"),
            ]
        return parameters
        

    def execute(self, parameters, messages):
        par = {p.name: p for p in parameters}
        # get the values
        fields = ["ID_A", "TEXT_A"]
        values = [
            par[f].value
            for f in fields
            ]
        # insert the new row
        with arcpy.da.InsertCursor(str(par["in_table"].value), fields) as cursor:
            cursor.insertRow(values)
        # set the output parameter
        par["out_table"].value = par["in_table"].value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1673948708318.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60527i0C9D156F96355FCA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1673948708318.png" alt="JohannesLindner_0-1673948708318.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1673948730329.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60528i87958A53F3BCE99A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1673948730329.png" alt="JohannesLindner_1-1673948730329.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_2-1673948815911.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60529i9481800E36805E78/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_2-1673948815911.png" alt="JohannesLindner_2-1673948815911.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jan 2023 09:47:14 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-01-17T09:47:14Z</dc:date>
    <item>
      <title>Is there a GP tool for inserting a row into a standalone table?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248566#M64278</link>
      <description>&lt;P&gt;Is there a geoprocessing tool for inserting a new row into a standalone table?&lt;/P&gt;&lt;P&gt;For example, in model builder, I want to add a new row to this non-spatial table:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_0-1673909753758.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60518iC531602387BE9199/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bud_0-1673909753758.png" alt="Bud_0-1673909753758.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;ArcGIS Pro 3.0.3&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 14:33:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248566#M64278</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-01-17T14:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: GP tool for inserting a row into a standalone table?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248567#M64279</link>
      <description>&lt;P&gt;No.&amp;nbsp; You would have to create a table, add your stuff and merge.&amp;nbsp; Python scripting would allow for an InsertCursor to update an existing table&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 23:16:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248567#M64279</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-01-16T23:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: GP tool for inserting a row into a standalone table?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248606#M64286</link>
      <description>&lt;P&gt;As Dan said, there's no out of the box tool. If you need that functionality in Model Builder, you have to create that tool yourself.&lt;/P&gt;&lt;P&gt;Below are two quick examples. You can save that script as a Python toolbox (.pyt), load that into ArcGIS Pro, and then drag the tools in to your model.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: cp1252 -*-

import arcpy


class Toolbox(object):
    def __init__(self):
        self.label = "Utility"
        self.alias = "utility"
        self.tools = [InsertRow, InsertRowIntoTableA]



class InsertRow(object):
    label="Insert Row"
    description="Inserts a row into a table"
    

    def getParameterInfo(self):
        parameters = [
            arcpy.Parameter(name="in_table", displayName="Table", datatype="DETable", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="row", displayName="Row", datatype="GPValueTable", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="out_table", displayName="Edited Table", datatype="DETable", parameterType="Derived", direction="Output"),
            ]
        parameters[1].columns = [
            ["GPString", "Field"],
            ["GPString", "Value"]
            ]
        return parameters
        

    def updateParameters(self, parameters):
        par = {p.name: p for p in parameters}
        
        in_table = str(par["in_table"].value)
        # reset fields if no table is selected
        if in_table == "None":
            par["row"].value = None
            return
        # get fields from the table
        target_fields = [
            f.name
            for f in arcpy.ListFields(in_table)
            if f.type not in ("OID", "GlobalID", "Geometry")
            ]
        # get currently loaded fields
        current_fields = []
        if par["row"].value is not None:
            current_fields = [
                f
                for f, v in par["row"].value
                ]
        # if these don't match, a different table was selected -&amp;gt; change fields
        if current_fields != target_fields:
            par["row"].value = [[f, None] for f in target_fields]


    def execute(self, parameters, messages):
        par = {p.name: p for p in parameters}
        # get fields with user input
        row = [
            [field, value]
            for field, value in par["row"].value
            if value not in ('', None)
            ]
        fields, values = list(zip(*row))
        # insert the new row
        # all values are str, but the InsertCursor should take care of the conversion
        with arcpy.da.InsertCursor(str(par["in_table"].value), fields) as cursor:
            cursor.insertRow(values)
        # set the output parameter
        par["out_table"].value = par["in_table"].value



class InsertRowIntoTableA(object):
    label="Insert Row into TableA"
    description="Inserts a row into TableA"
    

    def getParameterInfo(self):
        parameters = [
            arcpy.Parameter(name="in_table", displayName="TableA", datatype="DETable", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="ID_A", displayName="ID_A", datatype="GPLong", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="TEXT_A", displayName="TEXT_A", datatype="GPString", parameterType="Required", direction="Input"),
            arcpy.Parameter(name="out_table", displayName="Edited TableA", datatype="DETable", parameterType="Derived", direction="Output"),
            ]
        return parameters
        

    def execute(self, parameters, messages):
        par = {p.name: p for p in parameters}
        # get the values
        fields = ["ID_A", "TEXT_A"]
        values = [
            par[f].value
            for f in fields
            ]
        # insert the new row
        with arcpy.da.InsertCursor(str(par["in_table"].value), fields) as cursor:
            cursor.insertRow(values)
        # set the output parameter
        par["out_table"].value = par["in_table"].value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1673948708318.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60527i0C9D156F96355FCA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1673948708318.png" alt="JohannesLindner_0-1673948708318.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1673948730329.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60528i87958A53F3BCE99A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1673948730329.png" alt="JohannesLindner_1-1673948730329.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_2-1673948815911.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60529i9481800E36805E78/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_2-1673948815911.png" alt="JohannesLindner_2-1673948815911.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 09:47:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/is-there-a-gp-tool-for-inserting-a-row-into-a/m-p/1248606#M64286</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-17T09:47:14Z</dc:date>
    </item>
  </channel>
</rss>

