Skip to main content
14-Alexandrite
January 25, 2023
Solved

Can we automate report creation and send it as email attachment in ThingWorx?

  • January 25, 2023
  • 2 replies
  • 2772 views

Would like to generate a report based on the inputs from different sensors and then send this report as an email attachment.

Best answer by OldGoat

AP,

 

Our company is also a PTC partner; we have been sending html-formatted reports for several years now, and it is quite easy once you have ThingWorx set up with an Email Thing.  For all of the following, do NOT include the "<", ">" brackets.  Replace the contents with YOUR information!

 

STEP 1:  Set up a Notification Handler and include a service to handle the sending of an email.  The output of the service is a STRING:

See attached file "Stripped down Notification Handler.txt"

STEP 2:

Write your database thing service.  Our reports use stored procedures; run the DB Thing service as a QUERY, not a command!  This is where we query the data and format the HTML output.  If you're pulling data from sensors, just send the params to the stored proc instead.  View the attached file "Stripped Down Formatted Email Stored Procedure.txt"

 

Hope this helps some.  We also have javascript that allows us to export formatted data and send it as an email.  However, it isn't nearly as robust and it can't handle much data.  I've emailed up to 500 rows of data via the stored procedure with no problems.  You can also set up a scheduler to fire the handler on a scheduled basis.  So if you are storing data from sensors in a database, this is the easy way to send it.

 

 

2 replies

19-Tanzanite
January 25, 2023

The Mail Extension (PTC supported) has a service called "SendMessageWithAttachment" which allows you to send an email with attachment.

https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Extensibility/Mail.html

What are your requirements around the report (file format etc)? 

14-Alexandrite
January 25, 2023

A Pdf format or excel with the dataset should do.

OldGoat13-AquamarineAnswer
13-Aquamarine
February 8, 2023

AP,

 

Our company is also a PTC partner; we have been sending html-formatted reports for several years now, and it is quite easy once you have ThingWorx set up with an Email Thing.  For all of the following, do NOT include the "<", ">" brackets.  Replace the contents with YOUR information!

 

STEP 1:  Set up a Notification Handler and include a service to handle the sending of an email.  The output of the service is a STRING:

See attached file "Stripped down Notification Handler.txt"

STEP 2:

Write your database thing service.  Our reports use stored procedures; run the DB Thing service as a QUERY, not a command!  This is where we query the data and format the HTML output.  If you're pulling data from sensors, just send the params to the stored proc instead.  View the attached file "Stripped Down Formatted Email Stored Procedure.txt"

 

Hope this helps some.  We also have javascript that allows us to export formatted data and send it as an email.  However, it isn't nearly as robust and it can't handle much data.  I've emailed up to 500 rows of data via the stored procedure with no problems.  You can also set up a scheduler to fire the handler on a scheduled basis.  So if you are storing data from sensors in a database, this is the easy way to send it.