Tuesday, July 16, 2019

Get all records from AOT Query by enabling validTimeStateDateTimeRange in D365 FO/AX 2012

utcdatetime minDateTime = DateTimeUtil::minValue() , maxDateTime = DateTimeUtil::maxValue();


qry = new Query(QueryStr(TestQuery));
qry.validTimeStateDateTimeRange(minDateTime, maxDateTime); //In order display all records from ValidTimeState stamp table

Example: (Table Names)
HcmEmployment
HcmWorkerPositionAssignment
HcmWorkerEnrollBenefit

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)));
            }
        }

Get workflow participant User by document in D365 FO

PurchReqTable                               purchReqTable = PurchReqTable::findPurchReqId("002154");
        PurchReqLine                                purchReqLine;
        WorkflowParticipantExpenToken               workflowParticipantExpenToken;
        WorkflowParticipantExpenTokenLine           workflowParticipantExpenTokenLine;
        WorkflowUserList                            userList = WorkflowUserList::construct();       

        while select workflowParticipantExpenToken         
            where workflowParticipantExpenToken.ExpenditureDocumentType == WorkflowParticipantExpenDocumentType::PurchReq
                && workflowParticipantExpenToken.Name == "Project Manager"
        {
            info(strFmt("%1", workflowParticipantExpenToken.Name));

            while select ProjId, SourceDocumentLine, BuyingLegalEntity, RecId
                from purchReqLine
                where purchReqLine.PurchReqTable == purchReqTable.RecId
            {
                changecompany(CompanyInfo::findRecId(purchReqLine.BuyingLegalEntity).DataArea)
                {
                    workflowParticipantExpenTokenLine = WorkflowParticipantExpenTokenLine::findTokenLine(workflowParticipantExpenToken.RecId, purchReqLine.BuyingLegalEntity);

                    PurchReqWFExpendiParticipantProvider provider = PurchReqWFExpendiParticipantProvider::construct();
                    provider.documentType();

                    RefRecId    dimensionAttributeSetRecId;
                    MarkupTrans markupTrans;
                    if (purchReqLine.ProjId)
                    {
                        provider.resolveProjectDistributions(purchReqLine.SourceDocumentLine, workflowParticipantExpenTokenLine, userList);
                        dimensionAttributeSetRecId  = workflowParticipantExpenTokenLine.ProjectDimensionAttributeSet;
                    }
                    else
                    {
                        dimensionAttributeSetRecId  = workflowParticipantExpenTokenLine.OrganizationDimensionAttributeSet;
                    }

                    if (dimensionAttributeSetRecId)
                    {
                        provider.resolveDimensions(userList, purchReqLine.SourceDocumentLine, dimensionAttributeSetRecId);

                        while select SourceDocumentLine from  markupTrans where markupTrans.TransTableId == purchReqLine.TableId &&
                                                                            markupTrans.TransRecId   == purchReqLine.RecId
                        {
                            provider.resolveDimensions(userList, markupTrans.SourceDocumentLine, dimensionAttributeSetRecId);
                        }
                    }
                    //provider.Get
                }
            }
        }

        int i = 1;
        for(i=1;i<=userList.getCount();i++)
        {
            info(userList.get(i));
        }

Monday, July 1, 2019

Move LCS implementation projects to different Azure AD tenants

Get Week start and end Date based on YEAR & Week number

class SAN_DEMO
{       
    /// <summary>
    /// Class return week start and end Date based on YEAR & Week number
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        TransDate   setDate, startDate, endDate;
        int i;
        Year yr     = 2019;
        int week    = 5;
        int weekGet;
        int weekdays;
       
        setDate     = mkDate(01,01,yr);
        i           = dayOfWk(setDate);
        if(i<7)
        {
            setDate = setDate + (7-i);
            weekGet = week-1;
        }
        weekdays    = weekGet * 7;
        startDate   =  (setDate + weekdays)-7;
        endDate     =  (setDate + weekdays)-1;

        Info(strfmt("Year %1",yr));
        Info(strfmt("Week %1",week));
        Info(strfmt("Week Date Start %1",startDate));
        Info(strfmt("eeWk Date End %1",endDate));
    }

}

Filter Data on FORM event Handler in D365 FO

Filter Data on FORM event Handler in D365 FO

FormDS EVent Type: QueryExecuting

Create new Class and Paste Event Handler code

[FormDataSourceEventHandler(formDataSourceStr(<FormName>, <FormDSName>), FormDataSourceEventType::QueryExecuting)]
public static void <FormDSname_Default>_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
{
   sender.query().dataSourceName(sender.name()).addRange(fieldnum(<Table>,<FieldName>)).value(queryValue(<Value>));
}

FormHasMethod extension in D365FO

FormHasMethod extension in D365FO

Validating FORM HasMethod on Run time, including Form Extension HasMethod also in D365 FO

Class:
Global
Method:
formHasMethod

COC ->

using  System.Object;
using  Microsoft.Dynamics.Ax.Xpp;
using  System.Reflection;
[ExtensionOf(classStr(Global))]
final class Global_Extension
{
    static boolean formHasMethod(FormRun _fromRun, IdentifierName _methodName)
    {
        boolean flag = next formHasMethod(_fromRun, _methodName);

        if (flag==false)
        {
            flag= Global::VerifyformExtensionHasMethod(_fromRun, _methodName);
        }

        return flag;
    }

    private static boolean VerifyformExtensionHasMethod(FormRun _formRun, IdentifierName _methodName)
    {
        try
        {
            System.Object[] extensions = ExtensionClassSupport::GetExtensionsOnType(_formRun.GetType(), true);

            if (extensions)
            {
               System.Type    formExtensionType;
               MethodInfo    mInfo;
           
                var  bindingFlags = BindingFlags::Public | BindingFlags::Static | BindingFlags::IgnoreCase;

                for (int i = 0; i < extensions.Length; i++)
                {
                    formExtensionType = extensions.GetValue(i);

                    var info = formExtensionType.GetMethods(bindingFlags);

                    for (int J = 0; J < info .get_Length(); J++)
                    {
                        mInfo= info .getValue(J);
                        if (mInfo.Name == _methodName)
                        {
                            return true;
                        }
                    }
                }
            }
        }
        catch (Exception::CLRError)
        {
            error(CLRInterop::getLastException().ToString());
        }

        return false;
    }

}

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...