Friday, June 18, 2021

How to create custom workflow participant assignment provider type in D365 f&O

 Create a class and Write the following code : 

class GITS_DepartmentManagerParticipantProvider implements WorkflowParticipantProvider


    public WorkflowParticipantTokenList getParticipantTokens()


        WorkflowParticipantTokenList tokens = WorkflowParticipantTokenList::construct();

        tokens.add('DeptManager','Department Head');

        return tokens;


    public WorkflowUserList resolve(WorkflowContext _context,WorkflowParticipantToken _participantTokenName)


        str             deptName;

        anytype         tempWorker;

        DirPersonUser   personUser;

        HcmWorker       hcmWorker;

        OMOperatingUnit OMOperatingUnit;

        PurchTable      purchTable;

        WorkflowUserList userList = WorkflowUserList::construct();

        if (!_participantTokenName)


            throw Error("@SYS105453");



        select WorkerPurchPlacer from PurchTable

            where PurchTable.RecId == _context.parmRecId();

        deptName = HcmWorker::find(purchTable.WorkerPurchPlacer).primaryDepartmentName();


        select hcmWorker from OMOperatingUnit

            where OMOperatingUnit.Name == deptName

            &&    OMOperatingUnit.OMOperatingUnitType == OMOperatingUnitType::OMDepartment;

        tempWorker = OMOperatingUnit.hcmWorker;


        select User from personUser

            exists join hcmWorker

                where hcmWorker.Person == personUser.PersonParty

                &&    HcmWorker.RecId  == tempWorker;


        return userList;


    public static GITS_DepartmentManagerParticipantProvider construct()


        return new GITS_DepartmentManagerParticipantProvider();



Now create a "Workflow Participant Assignment Providers"

and put the help text and label "Purch Dept manager"

Available for all workflow template : No

Now in the provider class put in the name of the class that you created earlier i.e "GITS_DepartmentManagerParticipantProvider"

Now create a "Workflow type reference" and put in the then name of the workflow type that you want to provide the assignment on.