D365FO - Add new participant and type of participant to Participant workflow element

There are times when you want to add a new type of participant other than security role participants and user group participants, this post describes the steps to take and achieve this requirement.

This is the final output































Let's find out how did it work.

This is how each type of participant exists in AOT so a new Workflow Participant Assignment Provider needs to be created in order to see it in the Type of participant list as for this example 'Vendor invoice approval provider' is being added.


















Created a new Workflow Participant Assignment Provider with the following properties.

Available For All Workflow Templates = No [Just want to have this new Participant type vendor invoice approval workflow]

Added new workflow type and link it with VendInvoiceApprovalJournalTemplate which is the workflow type name for Vendor tax invoice approval journal workflow 











Each provider has a Provider class and here is an example of the class used for above created participant provider

class ECL_VendInvoiceWFParticipantProviderExpend  extends WorkflowParticipantProvider_Expend
{
    const str owner = 'OWNER';

    public WorkflowParticipantExpenDocumentType documentType()
    {
        return WorkflowParticipantExpenDocumentType::VendInvoice;
    }

    public WorkflowParticipantTokenList getParticipantTokens()
    {
        WorkflowParticipantTokenList tokenList = WorkflowParticipantTokenList::construct();

        tokenList = super();
        tokenList.add(owner, '@SYS77709');
        return tokenList;
    }

    /// <summary>
    ///     Resolves the vendor invoice line dimensions to a list of users
    /// </summary>
    /// <param name="_context">
    ///     An instance of the <c>WorkflowContext</c> class
    /// </param>
    /// <param name="_participantTokenName">
    ///     The participant token that is selected for a role-based assignment.
    /// </param>
    /// <returns>
    ///     An instance of the <c>WorkflowUserList</c> class that contains the enabled users from the token
    /// </returns>
    /// <exception cref="M:Exception::Error">
    ///     Participant token does not exist
    /// </exception>
    public WorkflowUserList resolve(WorkflowContext _context, WorkflowParticipantToken _participantTokenName)
    {
        LedgerJournalTable ledgerJournalTable = this.getLedgerJournalTableFromContext(_context);

        WorkflowUserList userList = WorkflowUserList::construct();
       
        if (_participantTokenName == owner)
        {
            userList.add(DirPersonUserEx::worker2UserId(LedgerJournalTable::findRecId(_context.parmRecId()).ECL_Originator));
        }

        return userList;
   
    }    

    /// <summary>
    /// Gets the <c>LedgerJournalTable</c> record from the workflow context.
    /// </summary>
    /// <param name = "_context">The workflow context.</param>
    /// <returns>A <c>LedgerJournalTable</c> record.</returns>
    private LedgerJournalTable getLedgerJournalTableFromContext(WorkflowContext _context)
    {
        LedgerJournalTable ledgerJournalTable;

        if (_context.parmTableId() == tableNum(LedgerJournalTable))
        {
            ledgerJournalTable = LedgerJournalTable::findRecId(_context.parmRecId());
        }
        else if (_context.parmTableId() == tableNum(LedgerJournalTable))
        {
            ledgerJournalTable = LedgerJournalTrans::findRecId(_context.parmRecId(), false).ledgerJournalTable();
        }

        return ledgerJournalTable;
    }

    /// <summary>
    /// Validates that the <c>WorkFlowContext</c> has the expected tables.
    /// </summary>
    /// <param name = "_context">The workflow context.</param>
    /// <returns>true if the expected tables are found; otherwise, false.</returns>
    private boolean doesContextHaveExpectedTable(WorkflowContext _context)
    {
        return _context.parmTableId() == tableNum(LedgerJournalTable) || _context.parmTableId() == tableNum(LedgerJournalTrans);
    }

    public static ECL_VendInvoiceWFParticipantProviderExpend construct()
    {
        return new ECL_VendInvoiceWFParticipantProviderExpend();
    }

}

If your interested to know how it used to work in AX 2012, follow this link https://dynamicsnavax.blogspot.com/2009/12/ax-workflow-direct-approver.html
Comment List
Related
Recommended