Create Table of Items from SmartObject List to send in workflow email

This question has been coming up a bit recently, so I thought I would share  one method of achieving this. There are other ways which I will mention briefly at the end.


Quite often we get a requirement to create a table of items to add to an email event or user task notification. There is no out of the box way to automatically convert a smartobject list method to a table, but we can use a combination of workflow event wizards to do this. In this example I will be using the "Create Reference", "For Each" and "Data Transfer" events. 


The method I describe below will take a smartobject list method and convert the results into a HTML table we can insert into an email body.


For this example I have created a Smartbox Smartobject with a few basic fields:




Lets look at each activity.




The first thing I am doing is creating a "Email Table" string data field and populating it with my table header structure using a data transfer event and an Expression inline function:




Then I create an Item Reference and point it to the Get List method of my smartobject:




Create Table Rows


This activity has a single Transfer Data event that does 2 things.






2. Create the table row


The second thing to do is add the table row for the current item. Using an expression I add the table row to the Email Data field (note that I add the Email Data field at the beginning of the expression).





To send the email I simply drop the Email Data field into my Email body. If you want to style your table you can create your own HTML template with its own styles.




Alternative Methods


Instead of using the Item Reference and For Each events, you could use the "Plan per slot (no destinations)" destination rule for an activity and add your smartobject list method there. You then select to return the "ID" property which will be accessible as the Activity Destination Instance - Instance Data field. You then add a smartobject event to the activity to to a read method and return the values you need to activity data fields. Then you use a similar pattern as above to create your table rows


Another method is to use XML and XSLT to firstly populate an XML data field with your list values and then use a Data Transfer "Transform Data with an XSL Template" to transform the XML into a HTML table. When you create the XML data field you will need to have an XML "template" to add as your initial value, or alternatively add an XSD as your XML schema and generate a sample XML.