0

I keep receiving the following error whenever running the following code below, is it the pathname that is incorrect or is it the actual function MakeTableView?

Traceback (most recent call last): File "\ServerName\UserHome$\user.name\My Documents\Contacts Table Clean Up.py", line 23, in arcpy.MakeTableView_management(contacts,"Contacts_tbl") File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 7047, in MakeTableView raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Table: Dataset C:\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Contacts does not exist or is not supported Failed to execute (MakeTableView).

import arcpy, os

contacts = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Contacts'
comTrkr = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\ComTrkr'
GISTrkr = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\GISTrkr'
gdb = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb'

arcpy.env.overwriteOutput=True


arcpy.MakeTableView_management(contacts,"Contacts_tbl")
contactsTblVw = "Contacts_tbl" 
contactsTblVw = arcpy.MakeTableView_management(contacts,"Contacts_tbl") 

#Update Contact_Status1 with'New' if value equals 'NULL'
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "Contact_Status1 IS NULL" )
arcpy.CalculateField_management(contactsTblVw, "Contact_Status1", '"NEW"' )

#Create output table to edit in Arcmap for Both Email fields
Contact_Email_Output = os.path.join(gdb, 'Export_Contact_Email') # To produce output named \\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Export_Contact_Email
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "Contact_Email LIKE '%@%'" )
arcpy.CopyRows_management(contactsTblVw, Contact_Email_Output)
contactsTblVw = arcpy.MakeTableView_management(contacts,"Contacts_tbl") 
#arcpy.AddField_management(Contact_Email_Output, "Editor", "TEXT")
#arcpy.EnableEditorTracking_management(Contact_Email_Output,'','','','ET_Date', "ADD_FIELDS")

arcpy.AddMessage("Contact_Email Table created, now on to Agency_Email")

Agency_Email_Output = os.path.join(gdb, 'Export_Agency_Email')
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "FROM contacts WHERE Agency_Email LIKE %@% " )
arcpy.CopyRows_management(contactsTblVw, Agency_Email_Output)
#arcpy.AddField_management(Contact_Email_Output, "Editor", "TEXT")
#arcpy.EnableEditorTracking_management(Agency_Email_Output,'','','','ET_Date', "ADD_FIELDS")

#String length for phone number.
Contact_Phone_Work_Output = os.path.join(gdb, 'Export_Contact_Phone_Work_Email')
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "FROM contacts WHERE LEN([Contact_Phone_Work]) = 12")
arcpy.SelectLayerByAttribute_management(contactsTblVw, "ADD_TO_SELECTION", "FROM contacts WHERE Contact_Phone_Work LIKE '%-%' ")
arcpy.CopyRows_management(contactsTblVw, Contact_Phone_Work_Output)

Agency_Phone_Output = os.path.join(gdb, 'Export_Agency_Phone_Email')        
arcpy.SelectLayerByAttribute_management(contactsTblVw, "NEW_SELECTION", "FROM contacts WHERE LEN(Agency_Phone_Work) = 12")
arcpy.SelectLayerByAttribute_management(contactsTblVw, "ADD_TO_SELECTION", "FROM contacts WHERE Agency_Phone_Work LIKE '%-%' ")
arcpy.CopyRows_management(contactsTblVw, Agency_Phone_Output)
  • I would imagine it is this portion of the path that is the problem "C:\\ServerName\UserHome$\user.name", you have $ and . in the path, something I would steer well clear of. Also you seem to be creating the tableview at least 3 times in your code, why? – Hornbydd Mar 13 '17 at 16:40
  • If it is a raw string you cannot have any "$,."? How would I put in the correct file path without this? I am creating a table view to create a output table of selected attributes from 3 different tables, can this be accomplished with one ? – Purplepeopleeater Mar 13 '17 at 16:51
  • First of all I would test the make table tool by running it in arcmap with exactly what you are putting in your script, just to confirm you don't have invalid characters in the file path. If it throws an error then if you want to continue to automate this you are going to have to move your data into an acceptable folder name (e.g. c:\GIS_DATA\Projects\Contact_Table_CleanUp). Reading your code you keep referring to the same base table so I would create it's view only once. – Hornbydd Mar 13 '17 at 17:03
  • I was able to successfully run the tool in Arcmap with no errors, am I adding too much data in the filepath then, such as the server name and user when I do not need to? Also if I only create Tableview once, will it still accomplish the 3 separate output tables? So will I be able to delete the following lines after the first , contactsTblVw = arcpy.MakeTableView_management(contacts,"Contacts_tbl") ? – Purplepeopleeater Mar 13 '17 at 17:12
  • Yes to deleting unnecessary calls for creating table view, your code will work as your selection type is always NEW SELECTION. I am going to edit your code in the answer below. – Hornbydd Mar 13 '17 at 19:25
2

Below is a modified version on your code, things to note are:

[1]

Create the view as follows:

arcpy.MakeTableView_management(contacts,"Contacts_tbl")

Note you had:

contactsTblVw = arcpy.MakeTableView_management(contacts,"Contacts_tbl")

You have confused yourself as contactsTblVw is a Results Object which amongst other things would contain the output of the tool. All tools return Result Objects. Your View of the table is an in-memory object which can be accessed simply by its name "Contacts_tbl"

[2]

You were referencing your table view incorrectly by passing in the Result Object, for example

arcpy.CopyRows_management(contactsTblVw, Contact_Email_Output)

Note the code now references the table view simply by it's name:

arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "LEN(Agency_Phone_Work) = 12")

[3]

Your where clause is wrong, you do not reference the table in the where clause, you had:

"FROM contacts WHERE Agency_Email LIKE %@% "

It should be:

"Agency_Email LIKE %@%"

[4]

Modified code is:

import arcpy, os

contacts = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Contacts'
comTrkr = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\ComTrkr'
GISTrkr = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\GISTrkr'
gdb = r'C:\\ServerName\UserHome$\user.name\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb'

arcpy.env.overwriteOutput=True
arcpy.MakeTableView_management(contacts,"Contacts_tbl")

#Update Contact_Status1 with'New' if value equals 'NULL'
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "Contact_Status1 IS NULL" )
arcpy.CalculateField_management("Contacts_tbl", "Contact_Status1", '"NEW"' )

#Create output table to edit in Arcmap for Both Email fields
Contact_Email_Output = os.path.join(gdb, 'Export_Contact_Email') # To produce output named \\My Documents\ArcGIS\Projects\Contact_Table_CleanUp\Test.gdb\Export_Contact_Email
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "Contact_Email LIKE '%@%'" )
arcpy.CopyRows_management("Contacts_tbl", Contact_Email_Output)
arcpy.AddMessage("Contact_Email Table created, now on to Agency_Email")
Agency_Email_Output = os.path.join(gdb, 'Export_Agency_Email')
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "Agency_Email LIKE %@% " )
arcpy.CopyRows_management("Contacts_tbl", Agency_Email_Output)

#String length for phone number.
Contact_Phone_Work_Output = os.path.join(gdb, 'Export_Contact_Phone_Work_Email')
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "FLEN([Contact_Phone_Work]) = 12")
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "ADD_TO_SELECTION", "Contact_Phone_Work LIKE '%-%' ")
arcpy.CopyRows_management("Contacts_tbl", Contact_Phone_Work_Output)

Agency_Phone_Output = os.path.join(gdb, 'Export_Agency_Phone_Email')
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "NEW_SELECTION", "LEN(Agency_Phone_Work) = 12")
arcpy.SelectLayerByAttribute_management("Contacts_tbl", "ADD_TO_SELECTION", "Agency_Phone_Work LIKE '%-%' ")
arcpy.CopyRows_management("Contacts_tbl", Agency_Phone_Output)
  • Thank you very much, I made the corrections but am still receiving the above error on line 21; arcpy.MakeTableView_management(contacts,"Contacts_tbl") So I don't know if it is the actual path names I inputted or not, since I was able to run the MakeTableView in Arcmap without a problem. – Purplepeopleeater Mar 13 '17 at 20:51
  • I guess try using a simplified folder path as I suggested in my original comments? – Hornbydd Mar 13 '17 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.