Showing posts with label COC. Show all posts
Showing posts with label COC. Show all posts

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

Product Receipt validation in Extension using COC D365FO



Product Receipt validation in Extension using COC D365FO



Using following code you can perform custom validation on product receipt using COC


[ExtensionOf(classstr(PurchPackingSlipJournalCreate))]
final class SLD_PurchPackingSlipJournalCreate_Extension
{

    protected boolean check()
    {
      
        PurchParameters     purchParam=PurchParameters::find();
        boolean flag=    next check();

            flag= flag && this.validatePackingSlip(flag);
      
        return flag;
    }

    public boolean validatePackingSlip(boolean flag)
    {
        if(flag && this.purchParmUpdate.DocumentStatus==DocumentStatus::PackingSlip)
        {
        
 

        }
        return flag;
    }

}

Transfer Order Shipment Validation D365FO


Transfer Order Shipment Validation in Extension COC


Yesterday, I received the requirement to put some custom validation during transfer order shipment.

As everyone knows that in D365FO over-layering is not allowed anymore. So I have performed this task in extension.

In extension, You have two options to perform this task.


1st-Way

Create the form extension and replace the shipment menu item with my custom menu item and after performing my successful custom validation call original menu items.

2nd-Way

Create extension class of  InventTransferUpdShip and override the check method using COC pattern and perform our custom validation.

I decided to go with COC and the following are the code snippet I have to write 



[ExtensionOf(classstr(InventTransferUpdShip))]
final class SLD_InventTransferUpdShip_Extension
{

    boolean validate()
    {
        
        boolean ok = next validate();

        
             ok=ok && this.validateTransferOrderShip(ok);
        
        return ok;
    }


  public boolean validateTransferOrderShip(boolean flag)

    {
        // write your validation here... 

     return flag;
  }

}

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