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

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...