vlantaca7

arcpy: get name of layer selected in AGOL

Discussion created by vlantaca7 on Aug 13, 2020

I am trying to create a geoprocessing service that can sense which layer that the user selected from. I have created a sample script to show what I have tried so far. It has a parameter called "Selection" which is of data type "Feature Set" and a string output parameter.

 

import arcpy

# params
feature_layer = arcpy.GetParameter(0)  # user selection

feature_layer_as_text = arcpy.GetParameterAsText(0)

desc = arcpy.Describe(feature_layer)

arcpy.AddMessage("baseName: {}".format(desc.baseName))
arcpy.AddMessage("catalogPath: {}".format(desc.catalogPath))
arcpy.AddMessage("children: {}".format(desc.children))
arcpy.AddMessage("childrenExpanded: {}".format(desc.childrenExpanded))
arcpy.AddMessage("dataElementType: {}".format(desc.dataElementType))
arcpy.AddMessage("dataType: {}".format(desc.dataType))
arcpy.AddMessage("extension: {}".format(desc.extension))
arcpy.AddMessage("file: {}".format(desc.file))
arcpy.AddMessage("fullPropsRetrieved: {}".format(desc.fullPropsRetrieved))
arcpy.AddMessage("metadataRetrieved: {}".format(desc.metadataRetrieved))
arcpy.AddMessage("name: {}".format(desc.name))
arcpy.AddMessage("path: {}".format(desc.path))
arcpy.AddMessage("feature_layer_as_text: {}".format(feature_layer_as_text))

arcpy.SetParameterAsText(1, \
      "baseName: {}".format(desc.baseName) \
    + "<br>catalogPath: {}".format(desc.catalogPath) \
    + "<br>children: {}".format(desc.children) \
    + "<br>childrenExpanded: {}".format(desc.childrenExpanded) \
    + "<br>dataElementType: {}".format(desc.dataElementType) \
    + "<br>dataType: {}".format(desc.dataType) \
    + "<br>extension: {}".format(desc.extension) \
    + "<br>file: {}".format(desc.file) \
    + "<br>fullPropsRetrieved: {}".format(desc.fullPropsRetrieved) \
    + "<br>metadataRetrieved: {}".format(desc.metadataRetrieved) \
    + "<br>name: {}".format(desc.name) \
    + "<br>path: {}".format(desc.path) \
    + "<br>" \
    + "<br>feature_layer_as_text: {}".format(feature_layer_as_text) \
)

 

When I run it in ArcMap, I can easily see which layer was selected, but when I publish as a geoprocessing script and use it in web app builder, the output string is something like:

 

baseName: {EA09D0E5-F384-4742-A3FB-1A865BAEF30A}
catalogPath: in_memory\{EA09D0E5-F384-4742-A3FB-1A865BAEF30A}
children: []
childrenExpanded: True
dataElementType: DEFeatureClass
dataType: FeatureRecordSetLayer
extension:
file: {EA09D0E5-F384-4742-A3FB-1A865BAEF30A}
fullPropsRetrieved: True
metadataRetrieved: False
name: {EA09D0E5-F384-4742-A3FB-1A865BAEF30A}
path: in_memory

feature_layer_as_text: in_memory\{EA09D0E5-F384-4742-A3FB-1A865BAEF30A}

 

One way I can tell which layer was selected is by using "arcpy.ListFields(feature_layer)" and figuring out from the fields which layer was selected. Is there a better or more direct way to fetch the name of the layer that was selected in web app builder?

Outcomes