Adding result table to ArcGIS Portal with web tool written in Python from ArcGIS Pro

06-10-2019 11:18 PM
New Contributor III

I have a web tool created in ArcGIS Pro, that is supposed to add both a shapefile and a table as a result. The shapefile adds fine, but the table doesn't show up (it does in ArcGIS Pro). Could someone help me?

# Find Varieties from Race
# Mette Balslev Greve
# June 2019

import arcpy as arcpy
import os
arcpy.env.overwriteOutput = True
outDir = arcpy.env.scratchFolder

# Inputs
race = arcpy.GetParameterAsText(0)

# Init - set variables and Clear previous selection of varieties
race_table = "Wheat_varieties_affected_by_races"
race_field = "Race"
variety_field_name = "Variety"
variety_fc_name = "DNA_variety_SR24"
arcpy.SelectLayerByAttribute_management(variety_fc_name, "CLEAR_SELECTION")

# Select records with the chosen race
selection = "{}= '{}'".format(race_field, race)
arcpy.SelectLayerByAttribute_management(race_table, "NEW_SELECTION", selection)

# Create table to hold varieties
variety_table = "Varieties.dbf"
variety_table_template = "Variety_template"
arcpy.CreateTable_management(outDir, variety_table, variety_table_template)
x = 0
full_path_table = os.path.join(outDir, variety_table)
cursor = arcpy.da.InsertCursor(full_path_table, "Variety")

# Step through records with the chosen race
for row in arcpy.SearchCursor(race_table):
   # Return the variety and check if there is a field with that name in the variety fc
   variety = row.getValue(variety_field_name)
   if arcpy.ListFields(variety_fc_name, variety):
      selection = "{} > 0".format(variety)
      arcpy.SelectLayerByAttribute_management(variety_fc_name, "ADD_TO_SELECTION", selection)

del cursor
output_layer_name = os.path.join(outDir, "Locations")
output_table_name = os.path.join(outDir, variety_table)
arcpy.CopyFeatures_management(variety_fc_name, output_layer_name)

arcpy.SetParameterAsText(1, output_layer_name)
arcpy.SetParameterAsText(2, output_table_name)

# Exit - Clear selection of races
arcpy.SelectLayerByAttribute_management(race_table, "CLEAR_SELECTION")

0 Kudos
0 Replies