Thursday, July 11, 2019

Get workflow delegate User for current user in D365 FO

WorkflowWorkItemDelegationParameters    delegationParameters;
        utcdatetime delegateDate = DateTimeUtil::utcNow();
        userId delegateUser;

        WorkflowTable                           workflowTable;
        SysWorkflowTable                        sysWorkflowTable;

       sysWorkflowTable = SysWorkflowTable::find(_workflowElementEventArgs.parmWorkflowContext().parmWorkflowCorrelationId());

        select firstonly workflowTable
            where workflowTable.Type == WorkflowConfigurationType::Definition
            && workflowTable.SequenceNumber == sysWorkflowTable.ConfigurationSequenceNumber;

        while select delegationParameters
            where delegationParameters.User == _currentUser
            && delegationParameters.Enabled == NoYes::Yes
                && delegationParameters.FromDate < delegateDate
                    && delegationParameters.ToDate > delegateDate
        {
            switch (delegationParameters.Type)
            {
                case WorkflowWorkItemDelegationType::All:
                    info("All "+delegationParameters.DelegateTo);
                    break;

                case WorkflowWorkItemDelegationType::Category:
                    if (delegationParameters.CategoryName == workflowTable.CategoryName)
                    {
                        info("module "+delegationParameters.DelegateTo);
                    }
                    break;

                case WorkflowWorkItemDelegationType::Configuration:
                    if (delegationParameters.ConfigurationSequenceNumber == workflowTable.SequenceNumber)
                    {
                        info("worklfow "+delegationParameters.DelegateTo);
                    }
                    break;

                default:
                    throw error(strFmt("@SYS122124", enum2str(delegationParameters.Type)));
            }
        }

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...