Add the ability to trigger a notification (to a specified e-mail address) when a new record is created in a hosted feature service though ArcGIS Online. This would be most beneficial when leveraging the GeoForm application for collecting information from the public. A bonus ability would be to initiate notification to different e-mails depending on a specific attribute. (For example, the GeoForm has a drop down menu (generated from a domain) for "Problem type", with the options "Pothole", "Tree Issue", etc. If the "Pothole" problem is chosen, then the email notification would go to the street department, if "Tree Issue" is chosen then the notification would go to the Urban Forester).
If you have the GeoEvent Extension for ArcGIS Server, you can achieve this. The steps are outlined in the help for the Citizen Problem Reporter application:
Real-time Problem Notifications - Citizen Problem Reporter | ArcGIS for Local Government
For those without the ability to access an Arc Server, this would be SUPER helpful!
I agree there is a need for this functionality without having to purchase the Geoevent extension. In my office we have accomplished this goal with a python script and a scheduled windows task. That being said, I had a conversation with someone at Esri and they acknowledged the need for this to be a part of the core functionality. One Idea I have, is to utilize Sever Object Interceptors. If I understand the way Portal/ArcGIS Online works, you could in theory create a SOI to live on any service on the GIS server behind the portal, and set it up so that the SOI is configurable where the user can input a list of emails, define what the SOI is listening for, and what message should be sent. Me team and I hope to begin R&Ding this soon.
Hi,
Would it be possible to know what functions you used in Python to write your script? We would love to be able to have an email notification as well after new entries are added.
Thanks in advance any help will be greatly appreciated!
This is how we do it:
# Import modules
import arcpy, time, sys, string, os, traceback, datetime, shutil, httplib, urllib, json, getpass, arcserver
import xml.dom.minidom as DOM
import xml.etree.ElementTree as ET
import smtplib
from email.MIMEText import MIMEText# Setting the arc py environment
ENV= arcpy.env
# End Arcpy Environment
# Setting the overwrite of existing features
ENV.overwriteOutput = True
# End Overwrite Setting# Variables
DateTime = datetime.datetime.now()
PreviousDateTime = readTextFile(txt_file, DateTime)
writelog(logFile, str(PreviousDateTime) + "\n")
D1 = "( LAST_EDITED_DATE >= '" + str(PreviousDateTime) + "' )"
FeatureClass = "\\feaureclasspath\\FeatureClass"
FeatureClassLayer = "FeatureClassLayer"FeatureClassFields = ["Name", "Email", "Address", "PhoneNumber"]
# End Variable Sectiontry:
FeatureClassLayer = arcpy.MakeFeatureLayer_management(FeatureClass, FeatureClassLayer )FeatureClassLayer = arcpy.SelectLayerByAttribute_management(FeatureClassLayer , "NEW_SELECTION", D1)
FeatureClassLayerCount = arcpy.GetCount_management(FeatureClassLayer)
if str(FeatureClassLayerCount) != str(0):
cursor = arcpy.da.SearchCursor(FeatureClassLayer, FeatureClassFields)
for row in cursor:
Name = GetValue(row, 0)
Email = GetValue(row, 1)
Address = GetValue(row, 2)
PhoneNumber = GetValue(row, 3)if EmailMessage == "":
EmailMessage += "The following drainage complaints have been made: " + "\n"
EmailMessage += "\n"
EmailMessage += "Name: " + Name + "\n"
EmailMessage += "Date: " + Date + "\n"
EmailMessage += "Email: " + Email + "\n"
EmailMessage += "Address: " + Address + "\n"
EmailMessage += "Phone Number: " + PhoneNumber + "\n"del cursor
del rowwritelog(logFile, "Process: Send Email" + "\n")
# Send Email
# This is the email notification piece [%]
#email error notification
smtpserver = 'email server'
AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1
smtpuser = '' # for SMTP AUTH, set SMTP username here
smtppass = '' # for SMTP AUTH, set SMTP password hereRECIPIENTS = ['email@email.com', 'email1@email1.com']
SENDER = 'email2@email2.com'
#msg = arcpy.GetMessages()***I think I need to look at the message variable
#msg = arcpy.GetMessage(0)# Brian Corrected this it is arcpy.GetMessage()
#msg += arcpy.GetMessage(2)# Brian Corrected this it is arcpy.GetMessage()
#msg += arcpy.GetMessage(3)# Brian Corrected this it is arcpy.GetMessage()
msg = MIMEText(EmailMessage) #***i pointed this mime thing at the message
msg['Subject'] = 'Edited Features briefing'
# Following headers are useful to show the email correctly
# in your recipient's email box, and to avoid being marked
# as spam. They are NOT essential to the sendmail call later
msg['From'] = "ArcGIS"
msg['Reply-to'] = "Name "
msg['To'] = "Email@Email.com"except:
print("Error:")
The concept is the same for dealing with feature services. We currently use a library from github called Portalpy in order to interact with the feature services. We are in the process of rewriting the process with the ArcGIS Python API. Please let me know if that helps or if you have any other questions. Thank you for everything and have a delightful day.
Sincerely,
Joe Guzi
Wow thank you so much, it's very appreciated!! I won't be able to look at it in more details for a little while but I have any questions I'll let you know.
Cheers
Chrystel
It would be best if it was a supported webhook, then you could easily set up different notification emails by Problem Type with Microsoft Flow, Integromat, or another. We currently also use a scheduled python script, but webhooks would be much easier and allow more functionality.
FYI: Webhook is a work in progress in online feature service. Most likely it will be available later this year.
Khaled Hassen
Online Feature Service Dev Lead
For anyone interested, here's the code I use to check for updates, send notifications, and update the feature. It uses the ArcGIS API for python (Python 3). Just turn on a scheduled task to run it how often you want.
It currently only sends internal notification, but if you understand what's going on, it would be easy to apply an external notification as well, so when a problem is marked as completed the email is then sent to the reportee with the email that they entered and then the email status is updated to sent or whatever you decide to use. Or, if there's no email you could change the emailstatus to "Unable to Send" or something like that. Your query would look like:
queryString = "status = 'Completed' AND emailstatus = 'WHATEVER_VALUE_YOU_PICKED_FOR_DEFAULT' "
EDIT: Depending on your version of "Pandas", you may have to use len(query_result1) instead of len(query_result1.features)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.