Form Data Source Field Method Override D365FO


Form Data Source Field Method Override D365FO



In this demo, I will show to create an extension class of form data source Field class and override method through COC.

Here is the annotation code to create COC



[ExtensionOf(formDataFieldStr(FormName, DataSourceName,DataFieldName))]


In this demo, we are using the HcmWorker form and creating Extension of DirPerson Data source field Personal Title..

[ExtensionOf(formDataFieldStr(HcmWorker, DirPerson,PersonalTitle))]

In actual code, you can find the method in the Hcmworker form 


 [DataField]
        class PersonalTitle
        {
            public Common lookupReference(FormReferenceControl _formReferenceControl)
            {
                return DirUtility::buildAffixReferenceControlLookup(_formReferenceControl, DirNameAffixType::PersonalPrefix);
            }

        }


Here is the code through which we create extensions.

[ExtensionOf(formDataFieldStr(HcmWorker, DirPerson,PersonalTitle))]
final class Demo_Extension
{
}


Here is the code through this we override the method.


[ExtensionOf(formDataFieldStr(HcmWorker, DirPerson,PersonalTitle))]
final class Demo_Extension
{
    public Common lookupReference(FormReferenceControl _formReferenceControl)
    {
        next lookupReference(_formReferenceControl);
        return DirUtility::buildAffixReferenceControlLookup(_formReferenceControl, DirNameAffixType::PersonalPrefix);
    }

}

Now perform build in sync on your module. enjoy


Form Data Source Method override COC D365FO


Form Data Source Method override COC D365FO


Here is the sample how can you override the form data-source event.

In this demo we have created the extension of HcmWorker form data-source (HcmWorker).


Here is the original method  of HcmWorker data-source 

    public boolean validateWrite()
        {
            boolean ret;

            ret = super();

            if (ret)
            {
                partyForm.validateWrite();
            }

            return ret;
        }

Here is the  code to create form data-source extension class 

[ExtensionOf(formdatasourcestr(HcmWorker, HcmWorker))]
final class Demo_Extension
{

}


Here is the code to override the data-source method through COC.

[ExtensionOf(formdatasourcestr(HcmWorker, HcmWorker))]
final class Demo_Extension
{
    public boolean validateWrite()
    {
        boolean ret;

        ret  =  next validateWrite();

        if (ret)
        {
                    
           /// do your code here
        }

        return ret;
    }

}


In last perform Build & Sync.

Important 
Feature available from Build 8.1 PU-20


Default parameters can be wrapped In extension classes COC


Default parameters can be wrapped In extension classes




In Build-8.1 you can override the default parameter by using class extension COC.


Code reference 

There is the method in HCMWORKER table isEmployee in which you can see the default value set with _validFrom & _validto.


  public HcmIsEmployee isEmployee(
        utcdatetime   _validFrom = DateTimeUtil::utcNow(),
        utcdatetime   _validTo = _validFrom
    )
    {
        HcmIsEmployee   hcmIsEmployee = NoYes::No;
        HcmEmployment   hcmEmployment;
        unchecked(Uncheck::XDS)
        {
            if (prmisDefault(_validFrom) && prmisDefault(_validTo))
            {
                select firstonly RecId from hcmEmployment
                where hcmEmployment.Worker == this.RecId
                &&    hcmEmployment.EmploymentType == HcmEmploymentType::Employee;
            }
            else if (_validFrom == _validTo)
            {
                select firstonly ValidTimeState(_validFrom) RecId from hcmEmployment
                where hcmEmployment.Worker == this.RecId
                &&    hcmEmployment.EmploymentType == HcmEmploymentType::Employee;
            }
            else
            {
                select firstonly ValidTimeState(_validFrom, _validTo) RecId from hcmEmployment
                where hcmEmployment.Worker == this.RecId
                &&    hcmEmployment.EmploymentType == HcmEmploymentType::Employee;
            }

            if (hcmEmployment.RecId != 0)
            {
                hcmIsEmployee = NoYes::Yes;
            }

            return hcmIsEmployee;
        }
    }


So we created extension class of Hcmworker with name of Demo_Extension and override the method using COC.



[ExtensionOf(tableStr(HcmWorker))]
final class Demo_Extension
{

    public HcmIsEmployee isEmployee(
        utcdatetime   _validFrom,
        utcdatetime   _validTo 
    )
    {
        HcmIsEmployee   hcmIsEmployee = NoYes::No;
        HcmEmployment   hcmEmployment;
      
        next isEmployee(_validFrom,_validTo);

               unchecked(Uncheck::XDS)
        {
           if (_validFrom == _validTo)
            {
                select firstonly ValidTimeState(_validFrom) RecId from hcmEmployment
                where hcmEmployment.Worker == this.RecId
                &&    hcmEmployment.EmploymentType == HcmEmploymentType::Employee;
            }
            else
            {
                select firstonly ValidTimeState(_validFrom, _validTo) RecId from hcmEmployment
                where hcmEmployment.Worker == this.RecId
                &&    hcmEmployment.EmploymentType == HcmEmploymentType::Employee;
            }

            if (hcmEmployment.RecId != 0)
            {
                hcmIsEmployee = NoYes::Yes;
            }

            return hcmIsEmployee;
        }
    }

}

Now perform build & Sync on your module..

New Module in Dynamics 365 for Finance & Operations


New Module in Dynamics 365 for Finance & Operations



Following are the Steps of Implementation:

Step-1 Create Extension of MainMenu.

Reference screenshot:

Step-2 Create new Menu and add two sub menu in it. enter label as per your requirement.

In demo I Use Name of new menu as FieldManagement
Reference screenshot:

Set Label
Reference screenshot:

Add new Sub-Menu
Reference screenshot:


Step-3 Create Menu reference in MainMenu Extension and set the reference of FieldManagement.
Reference screenshot:

Set reference of FieldManagement
Reference screenshot:


Step-4 Create Display method or Action or Out-Put as per your requirement.
set proper label and make it part of your sub-Menu of FieldManagement.

In demo we used display method 
Reference screenshot:


Set Display menu 
Reference screenshot:


Step-5 Perform Build of the appropriate module and check on UI
Reference screenshot:

Please feel free to contact me if you are facing any issue while trying to implement on this blog.


Create Contact Person for Vendor Or Customer AX 2012 & D365FO



Create Contact Person for Vendor Or Customer AX 2012 & D365FO



Important

In D365FO use ContactPersonSyncEntity class and in AX 2012 use ContactPersonEntity 



Using below code you can create contact person against Customer or Vendor in AX 2012 & D365FO.





class SLD_DemoInstance
{





    
    public static void main(Args _args)
    {

        // Declare variables: views.
        DirPartyContactInfoView contactInfo;
        DirPartyPostalAddressView postalAddress;

        // Declare variables: tables.
        ContactPerson contactperson;

        DirPartyTable partyTable = DirPartyTable::findRec(VendTable::find("S00038").Party);
   
        // Declare variables: classes.
        ContactPersonEntity contactPersonEntity;

   

  
        // Create and populate the contact person.

        contactPersonEntity = ContactPersonEntity::construct(contactPerson);
      
        contactPersonEntity.parmFirstName("FirstName");
        contactPersonEntity.parmMiddleName('M.');
        contactPersonEntity.parmLastName('Person');
        contactPersonEntity.parmAssistantName('AssistantName');
        contactPersonEntity.parmBillingInformation('Billing info');
        contactPersonEntity.parmCharacter('Character description');
        contactPersonEntity.parmComputerNetworkName('Computer network name');
        contactPersonEntity.parmContactForParty(partyTable.RecId);
        contactPersonEntity.parmContactMemo('Memo');
        contactPersonEntity.parmContactPersonId('CP64');
        contactPersonEntity.parmLoyalty('Loyalty');
        contactPersonEntity.parmMileage('Mileage');
        contactPersonEntity.parmOfficeLocation('Office location');
        contactPersonEntity.parmOutlookCategories('Outlook categories');
        contactPersonEntity.parmProfession('Profession');
        contactPersonEntity.parmSensitivity(smmSensitivity::Personal);
        contactPersonEntity.parmSpouse('Spouse');
        contactPersonEntity.parmTimeAvailableFrom(1000);
        contactPersonEntity.parmTimeAvailableTo(2000);
        contactPersonEntity.write();

        // Populate the postal address information by using the view.
        postalAddress.clear();
        postalAddress.Street = 'One Microsoft Way';
        postalAddress.City = 'Redmond';
        postalAddress.State = 'WA';
        postalAddress.ZipCode = '98052';
      
        postalAddress.Address="QAR";
        postalAddress.CountryRegionId = "Country Region ID";


        // Update the postal address information.
        contactPersonEntity.createOrUpdatePostalAddress(postalAddress);


        //phone

        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="Phone";
        contactInfo.Locator = "123456";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Phone;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);




      
        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="Email";
        contactInfo.Locator ="abcd@gmail.com";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Email;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);



        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="FAX";
        contactInfo.Locator ="98798789798";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Fax;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);

    }

}

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...