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

}

Thursday, June 27, 2019

Document Routing Agent D365FO

Document Routing Agent is an application which enables network printing scenarios in Dynamics 365 for Finance and Operations. It basically manages the spooling of documents to network printer devices.
Install/Configure Document Routing Agent:
Navigate for network printers page 
-> Organization administration > Setup > Network printers
       -> Options tab, in the Application group, 
       -> click -> Download document routing agent installer.
-> Once downloaded an executable file double click to install it on system.
-> Close all browser
-> Run -> Document Routing Agent
      -> Click -> Setting 
                  -> Enter Application Id, AAD tenant, D365 URL
-> Sign In Document Routing Agent using Credentials
-> On Document Routing Agent
      -> Click -> Printers
      -> Navigate to Network Printer
      -> Edit and Make Active to YES for necessary printers

Note:
'Microsoft Dynamics 365 Document Routing Service' service should run under "Domain admin user"

Friday, June 21, 2019

Export Text file and send to User in D365

      str     fileName = test.txt;
str _outputStr = "Test: san: son: Test001";
        TextStreamIo textStreamIo;
       
        textStreamIo = TextStreamIo::constructForWrite();

        if (textStreamIo)
        {
            textStreamIo.write(_outputStr);
            textStreamIo.finalize();
            File::SendFileToUser(textStreamIo.getStream(), fileName);
        }
        else
        {
            warning(strfmt("@SYS65356",fileName));
        }

Export label custom content

 GRID => Properties "Export Label" => "SalesReportMexico" To get download file with custom naming.