Python Script to mail/export printed versions of surveys?

2113
8
10-13-2017 04:57 AM
ICFAdmin
New Contributor II

Does anyone have a working version of a python (v3.x) to export and/or email a copy of new survey submissions. Specifically, here's the workflow I'm hoping to achieve.

  1. Script runs and checks for any reports during a specified time period.
  2. For each report that is found, the file created when a user clicks the "PRINT" button for a survey is created as a pdf and emailed to a specified address.
    • I assume we can customize the defaults for the print (e.g. large picture size etc).
    • Also assume it will use the Custom Print if it is available.
0 Kudos
8 Replies
by Anonymous User
Not applicable

Have you looked into this posting?

https://community.esri.com/groups/survey123/blog/2015/11/10/downloading-data-captured-with-survey123... 

Look toward the bottom of the posting and some of the comments contain information that you could potentially use.

0 Kudos
ICFAdmin
New Contributor II

Thank Mike, I have seen that but it doesn't solve the issue of wanting to get the formatted survey submission. I want to send the pdf file on to someone who doesn't have immediate access to the database and just needs something simple and easy to read. 

0 Kudos
by Anonymous User
Not applicable

ICF,

So, if we think about the option of the Blog, then could you have a hidden field; that worked behind that scenes, which contains the person's email that you want to send the "simple" PDF to. Maybe edit the python script to look for the field that contains the email address you want to send the PDF form to?

Even though this person does not have direct access, the PDF could still be created by the process/script and then emailed over to them; since you would hard code in the email address within the hidden field.

However, if the "person" you are sending the PDFs to could change to a list of multiple different people, then you would need to have some sort of trigger; if() function, that would allow the form to determine which individual would receive the PDF file through email based on answer to a question within the form.

There might also be another method you could use, if you trust the person filling out the survey, and that would be to use this post below to create an email that contains the information the end user needs to review within it that could be sent prior to submitting the form?

https://community.esri.com/thread/194609-not-your-standard-note-question-email-link 

I guess it just depends on the comfort of editing the script or the trust you have within the field crews submitting the email to the person(s) for review?

If this still does not help you, then sorry I could not be of any further assistance I hope that you do find a solution to this.

Good Luck!

Mike

0 Kudos
danbecker
Occasional Contributor III

We frequently run into this requirement, client wants to see the "field datasheet" submitted with the project deliverable, usually as an appendix of the report. Some client's accept a feat. class/table dump into a single excel table, some don't. In reality, a compiled single table that's produced by dumping the feat. classes and tables in the service is MUCH more useful, but none-the-less some people still like to see the raw "field datasheet".

What's even more problematic is that clients often want the newly collected data to be recorded on their existing field datasheet PDF/Word template...ugh.

I usually end up designing a template datasheet "form" in Excel. Alternatively, you can use a pre-existing template word doc that's just as easy to fill. Then, dump all feat. class/table data to a single Excel workbook separated into various worksheets, perhaps one for each related table. Then with a VGA macro, I open the blank template Excel/Word file, SAVE-AS and populate it by looping over the Excel worksheet(s), then export to PDF. The end product looks exactly like, or close to the client's field datasheet, minus the wet paper tears, field mud and illegible scribbles.

But...a 'PRINT' button would sure be nice...hint hint ESRI....

To the OP, this probably isnt' what you were looking for, but is just how we've done it in the past. Once you setup the macro once, it's not that difficult to edit it for other projects. You'll find a lot of similarities, main data table, ancillary related tables (repeats), ect...

BTW, I'm sure you could do this with Python also, but then you'll likely run into having to hunt for modules that can consume MS files.

0 Kudos
by Anonymous User
Not applicable

Dan, I feel your pain, but being able to recreate the field datasheets is a satisfying task in it's own sense. We have created fill able PDF files that we fill through using a mail merge procedure to push our data into the "field data sheets" that our clients and State Agencies want to see.

We have even gone so far as to recreate the data sheets within the ESRI "Report (rlf)" format and created the datasheets directly from the FGDB. I miss the crystal reports functionality within ESRI products had in the 3.x, 8.x, and 9.x days.

Okay enough of the hi-jacking of ICF's question.

0 Kudos
ICFAdmin
New Contributor II

Actually, in Survey123 there is a print function for each individual survey. You can even format it the way you like with a specialized Word file. We functionally need both things. A long term storage that we backup with a script but the more immediate need is PDF copy of the 'Print' Output so I can email it to a staff person in the field.

Think of it like a work order - it's actually a sighting sheet of an endangered species but we want to review it to see if we need to dispatch a person to the field to check out the sighting or call the person who saw it. I need something someone can open on a smart phone with limited internet connection and open the pdf - or open it later with no internet connection.

Essentially, I know I could output the data and reformat it into an email then go grab each of the associated photos and attach them and send the email - or I could just send that simple PDF that's already formatted cleanly and shows the associated photos.

ichivite-esristaff‌, do you know if the URL for the 'Print' for a record from Survey123 is something I can just parse so I could send a link to it or use python to download the PDF and attach it to an email?

0 Kudos
DornMoore
New Contributor II

Update folks!

We scripted a solution to this in Python and run the script on a schedule on a workstation/server. You can find our (crudely coded) solution over on Github.

GitHub - InternationalCraneFoundation/Survey123_reporter: Python template to check for new reports i... 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I have an old school way using data driven pages that I came up with 3+ years ago now.  Full code is here https://community.esri.com/thread/170563 

In my new job we flat out told people we cannot spend our limited resources developing ways to print out a piece of paper that will just go into a file cabinet never to be looked at again.  Moderate success at that, esp in government.  But at some point people need to move on from paper.  Usually when we provide a more modern solution we get them to convert.

0 Kudos