Component
NAME |
DynamicSender |
---|---|
CLASS_NAME |
com.CDRator.billing.workflow2.components.DynamicSender |
DESCRIPTION |
A component used for sending dynamic mail or SMS. |
PROJECT |
svn.cdrator.com/svn/dev/core/trunk/Rator |
Methods
METHOD |
execute |
---|---|
OBJECTS |
SUBSCRIPTION context |
DESCRIPTION |
Sends SMS or mail. |
PARAMETERS |
OUTCOME |
NOTES AND CONSIDERATIONS |
---|---|---|
The Parameter TEMPLATE_KEY is used to find the template from MailTemplate. The TEMPLATE_KEY is mandatory for the Dynamic Sender to Work. |
DONE |
It is possible to define who should receive the mail/sms at an earlier activity in the workflow. This can be done by adding a key "TEMPLATE_TO" to the context which defines the receiver. It is also possible to define the "TEMPLATE_TO" parameter on the activity itself. This will override the existing "TEMPLATE_TO" value in the context, if one already exists. Also TEMPLATE_KEY=<template name> and TEMPLATE_TYPE=EMAIL/SMS can be defined. ***IF@SOME_LABEL_NAME**** show this true value ***ELSE@SOME_LABEL_NAME*** Show this false value ***END@SOME_LABEL_NAME*** Block is used for reports. |
Sample config:
Sample parameters:
KEY |
VALUE |
COMMENT |
---|---|---|
TEMPLATE_TYPE |
Setting which type of communication should be sent |
|
TEMPLATE_KEY |
MOBILE_SIGNUP_ORDER_CONFIRM |
The reference (KEY) to the template |
WORK_VOICE_KEY |
TALE_PAKKE% |
A work variable to hold a string value |
CASE_HAS_VOICE_OPTION |
SUBSCRIPTION.getService.hasOptionLike(WORK_VOICE_KEY) |
Use Subscription from context to find out if the service has this option. ***IF@HAS_VOICE_OPTION*** |
WORK_VOICE_OPTION |
SUBSCRIPTION.getService.getOptionLike(WORK_VOICE_KEY) |
A temporary work object to hold the option. |
LABEL_VOICE_OPTION_NAME |
WORK_VOICE_OPTION.getProductOption.getName |
Prepare a option name LABEL for the template by using a previous work object. The result of invoking the parameter value, will be the end result. |
LABEL_VOICE_OPTION_DESCRIPTION |
WORK_VOICE_OPTION.getProductOption.getDescription |
Prepare a option description LABEL for the template by using a previous work object. The result of invoking the parameter value, will be the end result. |
Sample Template:
<html> <body> <p> ***IF@HAS_VOICE_OPTION*** You subscribed for this voice option: ***LABEL@VOICE_OPTION_NAME*** with description ***LABEL@VOICE_OPTION_DESCRIPTION*** ***ELSE@HAS_VOICE_OPTION*** You did not subscribe for any voice option ***END@HAS_VOICE_OPTION*** </p> </body> </html>
Using BLOCK Replacement
In order to use the Block Replacement functionality in the Dynamic Sender the BLOCK_<SOME_BLOCK_NAME> parameter has to be present, and the value has to be either a List of Hashtables or a String.
In case the value of the parameter is a String, the Block is simply replaced by the value of the parameter.
In case the value of the parameter is a List of Hashtables, the below section explains how to code and configure the Dynamic Sender Activity. Also, in the case that the List of Hashtables is created as a Context Object, the workflow has to be an In-Process workflow or, as a work-around, the List of Hashtables needs to be created as a Context Object in a Java Script activity in the activity just before the Dynamic Sender Activity which then needs to be an In-Process Activity. This is because the Hashtables inside the List cannot be persisted in the database.
The BLOCK Replacement functionality is available from CORE Release 8.5.
Replacing a BLOCK List
Lets assume that we want to send a list of users and their phone number in a email.
For this we could have a template which looks like the following.
Sample Template:
<html> <body> Here is a list of users and their Phone Number: <p> <!***BLOCK@USERS***> ***LABEL@FIRST_NAME*** ***LABEL@LAST_NAME*** ***LABEL@PHONE_NUMBER*** <!***BLOCK@USERS***> </p> </body></html>
So inside the Block USERS we have three labels we want to replace, namely, FIRST_NAME, LAST_NAME and PHONE_NUMBER.
In order for the Dynamic Sender to know which values should be replaced in the labels, a Hashtable needs to be created with the values for each User which should be included in the list. These Hashtables then need to be added to a List object which is assigned as the value of the BLOCK_<SOME_BLOCK_NAME> parameter (in this case BLOCK_USERS) in the Workflow Activity.
The List object would then typically be part of the Context for the workflow, but it is also possible to call a method on another Context Object which returns the needed List Object.
List Object is part of Context
If the List Object is part of the workflow context, the Dynamic Sender Activity Parameter for the above template sample could look like this:
KEY |
VALUE |
---|---|
BLOCK_USERS |
USER_BLOCK |
This of course means that a List Object has to exist as a Context Object with the Key "USER_BLOCK".
The List Object can either be added to Context when the Hookpoint is invoked, or it can be created and added to the context in a JavaScript Activity inside the workflow.
It is very important that the Hashtable only contains Strings, because assigning any other object as the value will cause the Dynamic Sender activity to fail.
The following shows a simple example of building a List Object to be added to the Context when invoking the Hookpoint:
Sample Java Code:
// Create List to hold all blocks ArrayList<Hashtable> blockList = new ArrayList<Hashtable>(); // Get all Users objects to create a Block for ArrayList<Users> users = getUsers(); // Run throuh all Users, create Hashtable with label names and values to be replaced, and add Hashtable to the List of Blocks for (Users user : users) { Hashtable block = new Hashtable(); block.put("FIRST_NAME", user.getFirstName()); block.put("LAST_NAME", user.getLastName()); block.put("PHONE_NUMBER", user.getSubscription().getService().get(0).getPhoneNumber()); blockList.add(block); } // Add the List of Blocks to the Context as a Context Object Hashtable<String, Object> contextObjects = new Hashtable<String, Object> (); contextObjects.put("USER_BLOCK", blockList);
The following shows a simple example of building a List Object to be added to the Context inside the workflow in a JavaScript Activity:
Sample JavaScript Activity Code:
// Create List to hold all blocks blockList = new java.util.ArrayList(); // Get all Users objects to create a Block for from the context users = WFCONTEXT.get("USERS"); // Run throuh all Users, create Hashtable with label names and values to be replaced, and add Hashtable to the List of Blocks for (int i = 0; i < users.size(); i++) { user = users.get(i); block = new java.util.Hashtable(); block.put("FIRST_NAME", user.getFirstName()); block.put("LAST_NAME", user.getLastName()); block.put("PHONE_NUMBER", user.getSubscription().getService().get(0).getPhoneNumber()); blockList.add(block); } // Add the List of Blocks to the Context WFCONTEXT.put("USER_BLOCK", blockList);
In case the Workflow is NOT an In-Process Workflow, the List of Hashtables must be added as a Context Object in a Java Script Activity just before the Dynamic Sender Activity. Furthermore, the Dynamic Sender Activity then has to be configured as an In-Process Activity. This way the two activities are processed in one transaction/session which means that it will work even though the List Context Object cannot be persisted in the database.
List Object is NOT part of Context but retrieved from another Object
In case the List Object is NOT in the context but returned from a method call on another Context Object, the Dynamic Sender Activity Parameter could look like this:
KEY |
VALUE |
---|---|
BLOCK_USERS |
SUBSCRIPTION.getUserBlockList |
In this case it is not necessary for the Workflow to be an In-Process Workflow.