Display method for table extension D365FO


A display method for table extension D365FO


As we all know there is no option to create a method in table extension and most of the time we have a requirement to create a display method.

Following are the steps.



Step-1  

Create a class Extension of the table where you can write the display method.

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
}


Step-2  

Create the display methods in the class 

public static class CustTable_Extension
{
[SysClientCacheDataMethodAttribute(true)]  
public static display Name custGroupName(CustTable _this)
{
return  CustGroup::find(_this.CustGroup).Name;
}
}



Send Email in CC AX-2012


Send Email in CC AX-2012


Most of the developer have requirement in their project to send email in CC and in default Dynamics AX-2012 & D365FO this functionality is not available.


But there is the Standard class SysEmailDistributor which is responsible to send the complete AX emails.. we can achieve our goal and send email in CC as well..


Open the class and check the process method where you can find  object of SysMailerNet class.

 SysMailerNetAddressField tos,tocc;  // declare a variable <tocc>

 mailer = new SysMailerNet();  

 tocc=mailer.ccs();   // get the SysMailerNetAddressField  object using this method

tocc.add("ShaikhSohailHussain@gmail.com");  //add email address on which you want to send email as CC.



Please feel free to contact me if you are facing any issue during implementation of this blog

Simple Look Up D365FO - AX-2012


Simple Look Up D365FO - AX-2012


Simple Look Up
Today we learn Simple Look Up in just 4 Step
Step: 1
Create a form Then add StringEdit Control in Design and override the lookup method.




Step: 2
Copy Paste this Code in the lookup method




Step :3
Create a AOT Query . In this tutorial my query name is  LookUpFormQuery 




Step :4
Compile Complete Project and Run the form




Event handler for QueryExecuting to filter data

Event handler for QueryExecuting to filter data


You can use the below code sample to filter data in query execution event

1. Copy Form ->Data source  >Event > onQueryExecuting.
2. Paste this code in the New class.



  [FormDataSourceEventHandler(formDataSourceStr(PayrollEmployerTaxRegion, PayrollEmployerTaxRegion), FormDataSourceEventType::QueryExecuting)]
    public static void PayrollEmployerTaxRegion_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)

    {

        sender.query().dataSourceName(sender.name()).addRange(fieldnum(PayrollEmployerTaxRegion,     CountryRegionId)).value(queryValue(LogisticsAddressCountryRegion::findByISOCode(SysCountryRegionCode::countryInfo(curext())).CountryRegionId));

    }

How to get Employee Dimensions


How to get Employee Dimensions

Here is the sample code to find the dimension by Name. In the below sample code we are using cost center Dimension for searching.




static void job1(Args _args)
    {
        HcmEmployment                         hcmEmployment;
        DimensionAttributeValueSetItem  setItem;
        DimensionAttributeValue              dimAttrValue;
        DimensionAttribute                      dimAttribute;
        ;

        dimAttribute    = DimensionAttribute::findByName('CostCenter');

        while select hcmEmployment
              join RecId, DisplayValue from setItem
              where setItem.DimensionAttributeValueSet ==
              hcmEmployment.DefaultDimension
              join dimAttrValue
              where dimAttrValue.RecId == setItem.DimensionAttributeValue &&
              dimAttrValue.DimensionAttribute == dimAttribute.RecId       &&
              dimAttrValue.IsDeleted == false
        {
            info(strFmt("Employee = %1  %2 = %3 ",
           HcmWorker::find(hcmEmployment.Worker).PersonnelNumber,
           dimAttribute.Name, setItem.DisplayValue));
        }
    }

How to override form control Lookup using extensions. D365FO

How to override form control Lookup using extensions. D365FO



In D365FO we have a bunch of events to subscribe on a form control level:





right click on lookup event of control to subscribe the event and paste in class.



[FormControlEventHandler(formControlStr(PayrollEmployerTaxRegion, Overview_StateId), FormControlEventType::Lookup)]
    public static void Overview_StateId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
                  // write your logic here
    }

Now to cancel parent event, D365FO provide a class FormControlCancelableSuperEventArgs

You can cancel the parent(Original event with below code)

        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;


        //cancel super() to prevent error.
        ce.CancelSuperCall();

// Here is the complete code sample to override form lookup and cancel the original code.


[FormControlEventHandler(formControlStr(PayrollEmployerTaxRegion, Overview_StateId), FormControlEventType::Lookup)]
    public static void Overview_StateId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysTableLookup      sysTableLookup  = SysTableLookup::newParameters(tableNum(LogisticsAddressState), sender);
        Query               query           = new Query();

        // Filter lookup to only show US states
        query.addDataSource(tableNum(LogisticsAddressState)).addRange(fieldNum(LogisticsAddressState, CountryRegionId)).value(LogisticsAddressCountryRegion::findByISOCode(SysCountryRegionCode::countryInfo(curext())).CountryRegionId);

        // Sort the lookup by state Id
        query.dataSourceTable(tableNum(LogisticsAddressState)).addOrderByField(fieldNum(LogisticsAddressState, StateId), SortOrder::Ascending);

        // Add fields
        sysTableLookup.addLookupfield(fieldNum(LogisticsAddressState, StateId));
        sysTableLookup.addLookupfield(fieldNum(LogisticsAddressState, Name));

        // Run lookup
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;

        //cancel super() to prevent error.
        ce.CancelSuperCall();
    } 

How to Get Current Company



How to Get Current Company

Hi,
Please use to get current logged in company with curExt();
Example :
static void curExtExample(Args _arg)
{
    str _CompanyId;
    ;
    _CompanyId= curExt();
      Info(_CompanyId);
}
You can also get the logged in company with below code
static void curExtExample(Args _arg)
{
    str _CompanyId;
    ;
   _CompanyId= CompanyInfo::Find().DataAreaId;
   Info(_CompanyId);
}

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