Scheduling a Task Notification Email
It is possible to send an automated email notifying users of all required workflow tasks by scheduling a bulk update that uses a business action. This email notification provides users with a single location for all assigned tasks, and enables users to better prioritize which tasks need to be addressed first.
Prerequisites
All of the configuration steps provided in this topic assume the user has knowledge of configuring collections, bulk updates, business actions, and workflows.
For more information on collections, refer to the Collections topic in the Getting Started documentation.
For more information on bulk updates, refer to the Bulk Updates topic in the in Bulk Updates documentation.
For more information on business actions, refer to the Business Actions topic in the Business Rules documentation.
For more information on workflows, refer to Workflows documentation.
Setting Up Email Notifications
To email a user their assigned tasks from a workflow the following elements must be created: a collection, a business action, and a bulk update. Once configured, an email notification containing a consolidation of all active tasks from one or more workflows is sent to the user(s) or user group(s) that are assigned the tasks.
To configure these, follow the directions listed below.
-
Create a collection with a single object in it that is permanent. The chosen permanent object needs to be something that will never be deleted from the system because it will be used in the scheduled bulk update. Additionally, if more than one object is added to the collection, multiple email notifications could be sent, which is not the desired outcome. The 'Primary Product Hierarchy' is used in this example.
-
Create a business action that checks the relevant workflow(s) and their state(s) for tasks. Configure the business action so that if the desired object types are in the designated workflow state(s), then an email will be created and sent to the designated user. In this example, the business action is called 'Bulk Notification.'
To create this business action, under 'Binds,' create variable names to bind to STEP Manager, Query Home, and Mail Home. In the example, the following binds were created:
Variable name
Bind to
manager
STEP Manager
qh
Query Home
mh
Mail Home
The following JavaScript can be used as a template:
Copy// Setup Query for items in a specific workflow state.
var workflow = manager.getWorkflowHome().getWorkflowByID("ItemCreation");
var supplierEnrichState = workflow.getStateByID("Supplier_Enrichment");
var c = com.stibo.query.condition.Conditions;
var querySpecification = qh.queryWorkflowTasks().where (
c.workflow().eq(workflow)
.and(c.state().eq(supplierEnrichState))
);
// Execute Query and create an email message with simple HTML table for items.
var query = querySpecification.execute();
var itemCount = 0;
var mailMessage = "Workflow: " + workflow.getTitle() + "<br/>";
mailMessage = mailMessage + "State: " + supplierEnrichState.getTitle() + "<br/><br/>";
mailMessage = mailMessage + "<table>\n<tr><th>ID</th><th>Name</th></tr>\n";
query.forEach(function(aTask) {
itemCount++;
var objID = aTask.getNode().getID();
var objTitle = aTask.getNode().getTitle();
mailMessage = mailMessage + "<tr><td>" + objID + "</td><td>" + objTitle + "</td></tr>\n";
return true;
});
mailMessage = mailMessage + "</table>\n";
// Send an email if any items are found. (If needed additional email addresses can be configured depending on products in a Task List.)
if (itemCount>0) {
var mail = mh.mail();
mail.addTo("UserL@stibosystems.com");
mail.subject("" + itemCount + " Products in Supplier_Enrichment");
mail.htmlMessage(mailMessage);
mail.send();
} -
Create a bulk update configuration that runs the business action just created, as shown in the screenshot below. Schedule the bulk update to run with the collection that was defined using the business action.
-
Save the Bulk Update configuration.
-
Navigate to the saved collection created earlier with only one object in it, and click on it. Go up to File > Bulk Update > Schedule Bulk Update.
-
Select the bulk update configuration just created and click through the wizard to set the schedule for the bulk update.
Since there is only one object in the collection configured on the bulk update, the business action will only run one single time.
-
When complete, an email is sent to the user listing the tasks they are responsible for in the designated workflow(s) and their state(s).