Select to view content in your preferred language

File Output Paramter in WebTool that was published from a Notebook in ArcGIS Online

2641
12
Jump to solution
07-22-2024 08:51 AM
Sven_Harpering
Esri Contributor

Hello everyone,

we have created a notebook in ArcGIS Online that creates a Word document based on various parameters. If we let the notebook run on its own, everything works. The output is written to the "arcgis/home" directory.

The next step would be to publish the notebook as a web tool in ArcGIS Online. To do this, we wanted to define an output parameter. The settings currently look like this:

Sven_Harpering_0-1721663506679.png

 

A first question would be what we have to specify as a default value in JSON format. According to the documentation, it has to be a URL to an existing output? Currently, we have simply uploaded the Word template as an item in ArcGIS Online and specified the URL to it.

Afterwards we added this snippet at the end of the notebook:

Sven_Harpering_1-1721663506683.png

 

The name of the variable equals the output variable name for the word file.

After publishing, we open the tool in map viewer and want to run it. Here we immediately notice that the output parameter does not appear in the GUI.

Sven_Harpering_2-1721663507188.png

 

The tool can still be started, but aborts with an error message in the output parameter area. 

Sven_Harpering_3-1721663506701.png

 

It seems that the error is in the output parameter section. Do you have any clue, what we are doing wrong in the whole output parameter section (Notebook config, etc.)? The input parameters work.

Best

Sven

 

Passionate about GIS and on the journey as an instructor for analytical insights.
1 Solution

Accepted Solutions
xlt208
by Esri Contributor
Esri Contributor

Hi @Sven_Harpering and @BenGiese,

Thank you for your patience! I was out of the office and could not respond sooner. 

Currently in Map Viewer, it is not possible to use selected features as an input to an analysis tool. That said, if you configure a web tool in Experience Builder's Analysis widget, you will then be able to pass in selected features from the map popups and widgets like Select, Table, etc.

Here is an example of setting a selected feature as analysis input from a map popup:

 

I hope this helps. Please let me know if you have other questions.

 

Thank you,

Lingtao 

View solution in original post

12 Replies
xlt208
by Esri Contributor
Esri Contributor

Hi @Sven_Harpering

Thanks for reaching out!

  1. For the default value, if there is a URL pointing to a file that you want to default to, you can specify the default value as {"url": "<url-to-file>"}. Alternatively, since it is okay to leave the URL blank, you can specify the value like this: {"url": ""}.
  2. It is expected that the output parameters will not appear in the GUI before you run the tool. If you expect a value from the web tool users, please create an input parameter for it. Output parameters are what the notebook web tool will output after the tool finishes running and cannot be specified by the users.
  3. Since the file ends up being a Microsoft Word item in the content, have you considered outputting it as a string instead of a file, with the string value pointing to the URL of the item's details page? That way, users can go to the item details page and proceed with sharing, downloading, or updating the item. 
  4. Could you please copy the error message in the last screenshot and paste it as text here? We are unable to read the error message very clearly. (The screenshot might have been compressed by the website when it was uploaded.)

Looking forward to hearing back from you!

 

Lingtao

Product Engineer for ArcGIS Notebooks

 

BenGiese
Emerging Contributor

Hi @xlt208 ,

I'm working with Sven on this project. Thanks for your guidance; it has already helped us a lot.

We are currently keeping {"url": ""} empty and have defined an input where the user can specify the output name. The .docx files are published as items in ArcGIS Online at the end. Our script creates a .docx file for each feature.

You asked for the error message. I don’t have access to it anymore because my script is working now. I think it was a problem with the specification of the output parameters and the URL we were pointing towards.

We want the user to select a feature on a map in the last step. The reports should then be created only for the selected features. This is possible in Experience Builder.

 

BenGiese_1-1721728746492.png

 

Apparently, the problem is that the selected features are not being passed along. Our input parameter is a feature set, but we still need to convert it to a feature set in the script. The selected features are being lost in the input. Do you have any idea what we need to set up to ensure the selection is considered?

This is our setting for the input features paramter:

BenGiese_2-1721728752264.png

This is the Code: 

 

selected_damage = {
	"url": "https://services3.arcgis.com/JhD3NyxTJcNiae8J/arcgis/rest/services/survey123_25027c5ec6294a65a7a851be8740f6f8_results/FeatureServer/0"
}

#get the url and return a feature layer
feature_layer_url = selected_damage["url"]
feature_layer = FeatureLayer(feature_layer_url)

# Get the Feature set
feature_set = feature_layer.query(where="1=1")  # Abfrage mit allen Features

 

Until now this only returns a feature set with all features of the feature layer, not the selected. 

 

0 Kudos
Sven_Harpering
Esri Contributor

Hi @xlt208@BenGiese,

here is the error message:

Sven_Harpering_0-1721732328078.png

As Ben wrote, we have updatet the script already, so we are not using the output parameter any longer. But maybe it is still interesting for you.

 

Best

Sven

 

Passionate about GIS and on the journey as an instructor for analytical insights.
0 Kudos
Sven_Harpering
Esri Contributor

Hi @xlt208,

do you have any further clue for us?

Thx

Sven

Passionate about GIS and on the journey as an instructor for analytical insights.
0 Kudos
xlt208
by Esri Contributor
Esri Contributor

Hi @Sven_Harpering and @BenGiese,

Thank you for your patience! I was out of the office and could not respond sooner. 

Currently in Map Viewer, it is not possible to use selected features as an input to an analysis tool. That said, if you configure a web tool in Experience Builder's Analysis widget, you will then be able to pass in selected features from the map popups and widgets like Select, Table, etc.

Here is an example of setting a selected feature as analysis input from a map popup:

 

I hope this helps. Please let me know if you have other questions.

 

Thank you,

Lingtao 

Alex_Rodriguez
Emerging Contributor

Hey Lingtao,

i'm trying to export a list of groupIDs, names, and owners to a csv file.  I'm fine with that CSV file ending up in the HOME folder.  But when I publish, then try to run the tool, it fails.  The error message suggests I can't write to the output path..which is HOME. 
Any suggestions?

0 Kudos
xlt208
by Esri Contributor
Esri Contributor

Hi @Alex_Rodriguez,

It sounds like your code was attempting to write the CSV file into the /arcgis/home directory. Is that correct? This directory is unavailable for notebook web tools. You may need to change the output location to a relative path. Here is an example:

csv_file = open("group_info.csv", "w")
csv_file.write("xxx")
csv_file.close()
output_csv = {"url": "group_info.csv"} # output parameter of the "File" type

Looking forward to hearing how it goes.

 

Thank you!

Lingtao

0 Kudos
Alex_Rodriguez
Emerging Contributor

Hey Lingtao,

Thanks for your reply. I added the line of code you suggested (assuming I interpreted your post correctly).
Here's what I ended up with:

f = open("/arcgis/home/ExportFiles/GroupsList.csv", 
     mode='a', 
     encoding='utf-8')
f.write("whatever I'm writing to the file, line by line")
f.close()
output_csv = {"url": "/arcgis/home/ExportFiles/GroupsList.csv")

Where: 
"ExportFiles" is a folder I created to store these output files

I'm opening/closing the output file each time I write to it.  I imagine that's not as efficient as it could be...but that's what I'm doing.

End result:    I'm getting the same error.

 

0 Kudos
Alex_Rodriguez
Emerging Contributor

Okay, downloaded a sample notebook that creates 2 CSV files.   Ran it as a notebook, works fine.
Published it and ran it as a tool.  Failed...for the same reason as mine.
So, as you mentioned, HOME is evidently not available to the tool.   But I can't find documentation that indicates what IS available to a tool.

Can anyone clue me in to what folder structure is available to a tool for writing files?  Your assistance would be greatly appreciated.

 

alex

0 Kudos