How To Create a Custom Work Queue Action

How To Create a Custom Work Queue Action

When changing a record’s state or value is not enough for the work queue command, you need to create a custom action.

Custom action is essentially a sequential workflow assigned to the work queue.

In this example we will create a sequential workflow, that will close a Sales Order. While closing the sales order it will have to update multiple data at once, so we could not use a simple state change work queue action.

1. Create a Sequential Workflow

The sequential workflow will consist of:

  • Input Work Queue Context
  • SalesOrder context
  • Steps to load/transform/save the sales order
  • Steps to delete the item from the work queue

Contexts

Create the following Contexts in the sequential workflow:

Name Data Type Data Structure Remarks
WQ_SalesOrder Xml WQ_SalesOrder This is an input context that will contain the selected queue entry.
SalesOrder Xml SalesOrder This is a context where we will load the sales order connected to the work queue entry, modify its values and save back to the database.

Tasks

Right click on the SalesOrder context and select Actions > Load/Transform/Save Tasks.

This will create 3 tasks where you will need to fill in some missing parameters.

  • Under the step 01 open the DataStructure node and set the FilterSet property so it loads by primary key (typically named GetId). If you do not have such a Filter Set defined, you have to define it first.

  • Under the step 01 open the Parameters node**,** right click on it and select New > Context Store Reference and fill in the following values:

    Property Name Value Remarks
    Name SalesOrder_parId This is the parameter name that is requested by the data structure’s filter set that you selected. In your case you have to update this name according to your own data structure.
    ContextStore WQ_SalesOrder Here select the work queue entry. There from we will get the Id of the record we need to update.
    XPath /ROOT/WorkQueueEntry/@refId This is the XPath pointing to the Id of the sales order in the work queue entry.
  • Now create a transformation that will actually update your data. It can look something like this:

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="SalesOrder"/>
        </ROOT>
    </xsl:template>
    <xsl:template match="SalesOrder">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:attribute name="refSalesOrderStateId"><xsl:value-of select="AS:GetConstant('SalesOrder_Closed')"/></xsl:attribute>
            <xsl:copy-of select="*[name() != 'SalesOrderDetail']"/>
            <xsl:apply-templates select="SalesOrderDetail"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="SalesOrderDetail">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:attribute name="DateClosed"><xsl:value-of select="date:date-time()"/></xsl:attribute>
            <xsl:copy-of select="*"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

2. Assign to the Work Queue Class

3. Configure the Work Queue