Extending Work Queue Notifications With a New Contact Type

Extending Work Queue Notifications With a New Contact Type

It comes handy when you want to send notifications to recipients that are to be computed dynamically based on the data. E.g. send a notification to all staff of order’s business unit.

Can be also used to generate senders as well.

Step-by-step guide

  1. Insert a new notification contact type into a database
    In our example we are going to extract a customer email from a booking (rental transaction). So this type of contact can be used in many notifications which involves that booking - e.g. various state changes (new, reservation expired, has been closed, etc.)

    If you have a multi-lingual application, you can also add translations of the newly created contact type by inserting the records into WorkQueueNotificationContactType_l10n table.

  2. Extend GetNotificationContacts Workflow to handle out new contact type
    The workflow is called from within WorkQueue notification subsystem.

    9404531_663x343

    The picture shows the target state of workflow. So that’s it. The next steps will describe how to achive this result.

  3. Create a new data constant with an Id of your new notification data type
    Data > Constants > YouPackageName > New > Data Constant

  4. Create an XPath rule to identify your contact type
    Business Logic > Rules > YourPackageName > New > Start Rule
    This rule we are going to use in the step of workflow in order to identify and process only notifications with our notification contact type selected.

  5. In GetNotificationContact workflow create a special step for processing our contact type.
    Find GetNotificationContact, right click and select New > Block (Transaction)

    9404534_615x371

Create a workflow step/s with actual transformation (creation of a new AsapNotificationContact data structure)
GetNotificationContacts has the following context stores:

9404537_295x122

Context Store Type
AsapNotificationContactData Output

A data structure with a list of found contacts. This context store is a return one and it has to be filled with contacts.

![9404538_226x52](upload://xgHdoVGDFKPqYu8a583TfdPKOe2.png)

![9404549_217x124](upload://6FicNnO5tzyHqTrmuzKSorSOOiy.png)

asapNotificationChannelTypeId Input Email/Sms etc. (input)
context Input Data from a data structure defined in our WorkQueue class as a NotificationStructure. If not defined, the context will contain the "raw" data of the WorkQueueEntry.
value Input A value passed from Notification Senders/Notification Recipients tab on the Work Queue screen. It is an additional control value that can be added by a user in the Work Queue notification configuration screen.
workQueueNotificationContactTypeId Input A type of notification contact. We already used this value for checking contact type in step 5.

The transformation has to have a target context store set to AsapNotificationContactData. We can create the transformation step by rigth-clicking on AsapNotificationContactData contextstore and choose Action > New Transform Task.Then we have to set a Data parameter of that transformation to Context so we have set the input for the transformation.

9404540_300x75

Now move the newly created transformation task under block task with the NotificationContactType condition.

Finally create a transformation that will produce contact data simillary as in the following example.

Transformation example

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:AS="http://schema.advantages.cz/AsapFunctions"
    xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="AS date">

    <xsl:template match="ROOT">
        <ROOT>
            <xsl:apply-templates select="RentalTransaction"/>
        </ROOT>
    </xsl:template>

    <xsl:template match="RentalTransaction">
        <AsapNotificationContact
            ContactIdentification="{@CustomerEmail}"
            Name="{@CustomerName}"
            refSalutationId="{@refCustomerSalutationId}"
        >
            <xsl:if test="string(@refCustomerLanguageId) != ''">
                <xsl:attribute name="LanguageTagIETF">
                    <xsl:value-of select="AS:LookupValue('7823d8af-4968-48c3-a772-287475d429e1',@refCustomerLanguageId)"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="string(@refCustomerSalutationId) != ''">
                <xsl:attribute name="Salutation">
                    <xsl:value-of select="AS:LookupValue('67d3131e-a81d-462d-830c-b67fdb2d6bb8', @refCustomerSalutationId)"/>
                </xsl:attribute>
            </xsl:if>
        </AsapNotificationContact>
    </xsl:template>
</xsl:stylesheet>

AsapNotificationContact entity Description

Name Mandatory Description
ContactIdentification x Identification of a contact. Email in case of e-mail notification channel, phone number in case of SMS channel, etc.
Name Name of contact (e.g. FirstName and Name, or just Name).
LanguageTagIETF Language tag, e.g. ‘en-US’ or ‘de-DE’.
refSalutationId Contact salutation identifier (Guid). Useful in a multilingual application.
Salutation Contact salutation (string).

Example

Example of notification template using generated contacts

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:AS="http://schema.advantages.cz/AsapFunctions"
xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="AS date">
<xsl:param name="RecipientRow" />

<xsl:template match="ROOT">

    <ROOT>
          <AsapNotification>
                 <xsl:attribute name="Subject">
                      <xsl:value-of select="concat('Rental Transaction ', /ROOT/RentalTransaction/@Number,' Booked')"/>
                 </xsl:attribute>
                 <Body>&lt;html&gt;
<xsl:variable name="salutation">
  <xsl:choose>
    <xsl:when test="string($RecipientRow/row/@refSalutationId) = ''">
      <xsl:value-of select="'Mr/Ms'" />
    </xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="AS:LookupValue('67d3131e-a81d-462d-830c-b67fdb2d6bb8',$RecipientRow/row/@refSalutationId)"/>
    </xsl:otherwise>
  </xsl:choose>
...