Select to view content in your preferred language

Hosted Feature layer notifications

2604
24
04-13-2023 11:58 AM
SLouq
by MVP Regular Contributor
MVP Regular Contributor

I have workers in the field doing hydrant inspections using Survey123. When they submit the form, it updates a hosted feature layer which I can access in my ArcGIS Pro document. I was wondering since I update a hydrant feature class with the information they are publishing in the hosted feature layer, is there a way for me to get a notification whenever that hosted feature layer is updated? Instead of me just having to remember to check it everyday to see if it's been updated.

Thanks

0 Kudos
24 Replies
RhettZufelt
MVP Notable Contributor

If you have office 365 login, you can set up power automate Survey 123 notification that does just that.

I have also had success with scheduled python tasks and this post.

R_

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

Thank you !

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

I copied the python code into a notepad .txt doc and saved it with the .py extension. I entered my hosted feature layer URL into the script and I had my IT person replace all the blue text with the corresponding server info so the script could access the server. Had my inspection crew submit a survey but recieved no email notification. 

My question is for the line in the script:  "layergens": "layergens_ms.json" 

Do I leave that line as is or do I need to replace layergen with the name of my hosted feature layer? 

 

0 Kudos
RhettZufelt
MVP Notable Contributor

If you follow the directions linked above, Step 1 of the script part is to  download the script:

RhettZufelt_0-1681930630698.png

That zip file has the python script AND the init.json file.  The init.json file is what needs to be modified with the blue items from the link above, the included script is what you run in python3.

Then:

RhettZufelt_1-1681930733165.pngYou need to run the script once at firsts, this will create the layergens_ms.json file, which captures the 'state' of the HFL at that time.   

Unlike PowerAutomate, this "script" won't detect when a change is made automatically, the python script has to run in order for it to "check" for changes. So, schedule the script to run as often as you want. (I had it run every minute when testing).   When it runs, it will compare the state on AGOL to the state last captured in the layergens file and will report if any changes were made.

Doesn't matter what you name the layergens_ms.json file, but, since I use this to detect change in more than one layer, I usually include the layer name so it is easier to keep track of. 

 

   (ex.  "layergens": "layergens_hydrants.json")

 

So, the first time you run it, it creates the layergens file and will not notify you of any changes.  After that, anytime it runs, it checks with the layergen to see if anything has changed, if so, it sends the email, and updates the layergen to include the recent changes so that same update doesn't trigger it again.

R_

 

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

Now I see. I didn't see where the download button was in the upper right of the page.  Now that I have found the python DetectChanges.py and init.json file and downloaded it to my computer do I need to change anything in the DetectChanges.py script or just in the init.json file?

I ran the DetectChanges.py script using IDLE(ArcGIS Pro) and it gave me the error:

SystemExit: 1 Unable to generate token. Invalid Username or Password (in getToken)

Does that mean I'm not entering the right username and password in the init.json file? 

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

I may have answered my own question. I got the python script to run without throwing an error. Now I just have to get my IT people to put the DetectChanges.py and the init.json files in the right location and set the Task Scheduler up so it will run the script for me. 

Thanks!

0 Kudos
RhettZufelt
MVP Notable Contributor

You can test it manually first to make sure it is working correctly, then task scheduler it.

Once you have ran it once, it will create the layergen file for you. 

Then, to test it, you can have your crew submit another test survey, then just run the script in IDLE again.

R_

PS, unlike the power automate connector, this will notify you when the HFS has changed (editing in map viewer, Pro, etc) wheras the Survey 123 connector only detects changes made with Survey 123.

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

Thank for replying to my questions on this!

I ran the python script in IDLE and it outputs this file.

SLouq_0-1682010339248.png

I was getting the error I specified in a reply yesterday of Unable to generate token but then got it to output this file. Does this look correct?

My IT guy is telling me this needs to be run on the database server.

 

0 Kudos
RhettZufelt
MVP Notable Contributor

The first time you run it, should look like this:

RhettZufelt_0-1682011038650.png

 

Then, if you make any change to the data and run again:

RhettZufelt_1-1682011083530.png

and get an email like:

RhettZufelt_2-1682011170544.png

If running as a scheduled task, you don't see IDLE, so will just get the email when something chaged.

I am able to run this from any computer that I have Pro installed on (since it installs python3 and the requests module).  But, doesn't even need Pro, just python3 and request module.

It looks like you are having an issue reading the json config file.  Is your init.json file in the same directory as the DetectChanges.py file?

Is it sensitive, or can you share the text content of your init.json file to help troubleshoot? (Can direct message me if you like)

R_

0 Kudos