Select to view content in your preferred language

Can you input a parameter value after starting a script tool?

2372
11
Jump to solution
10-26-2021 12:25 PM
tigerwoulds
Occasional Contributor III

I have a python script that will edit all map service capabilities for all services on a federated GIS Server. The script will print out a list of GIS Servers in a federated Enterprise environment > prompt the user to input an integer associated with the index of which GIS Server they want to operate on > all map services are updated on that server. 

I am trying to convert this to a script tool in ArcGIS Pro. My script requires the user to input a value after it prints the list of GIS Servers, so it knows which server to run the remaining script on. Is this possible using a script tool? If so, how can I do this? 

0 Kudos
11 Replies
tigerwoulds
Occasional Contributor III

I need the the index of the GIS Server the user selects as a variable to use later on in my execute. Using parameters[3].valueAsText  does not provide this. 

I did figure this out though, so thank you for you help!

def execute(self, parameters, messages):
"""The source code of the tool."""
# Input Parameters
startTime = time.time()
portal = parameters[0].valueAsText
user = parameters[1].valueAsText
password = parameters[2].valueAsText
# Based on which server the user selects for the GIS Server drop down, get the Index Number for that to pass into the rest of the script
if parameters[2].value: # If the password field is filled in
gis = GIS(portal, user, password, verify_cert=False) # Connect to the GIS Portal
serverList = gis.admin.servers.list() # Build a list of GIS Servers
# Convert each item in the serverList to a string and add it to a new list
newList = []
for item in serverList:
myString = str(item)
newList.append(myString)
x = newList.index(parameters[3].valueAsText) # Get index value from the server list based on which server the user selects
...

 

0 Kudos
by Anonymous User
Not applicable

If you need the index for other things in your code, you can create a 'read-only' kind of parameter parameters[4](?) and set it when you get the index.

0 Kudos