28 June 2021

How to get the control name in D365FO

 PurchId purchId = purchCreateOrder.design().controlName(formControlStr(PurchCreateOrder,PurchTable_PurchId)).valueStr());

27 June 2021

X++ code to get contact person Vendor/Customer which is specified in the Purchasing demographics AX 2012 / D365 FO

Table relations:

contactPerson.CONTACTPERSONID == VendTable.contactPersonId

DirPartyTable.RecId  == ContactPerson.Party

Below is the single line logic to get it.

 ContactPerson::find(VendTable::find("US-104").ContactPersonId).personName()




17 May 2021

How to override lookup form control methods using extensions / events in d365FO

 How to stop standard lookup and override the new lookup method.

FormControlCancelableSuperEventArgs formControlCancelSuper = e as FormControlCancelableSuperEventArgs;

        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(ProjCategory), sender);

      

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

        formControlCancelSuper.CancelSuperCall();

11 May 2021

X++ code to check Fiscal calendar period in AX 2012 and D365FO

X++ code to check Fiscal calendar period in AX 2012 and D365FO 

used to get the period status (Open, On hold and Closed)

  public static boolean checkFiscalCalendarPeriod(TransDate _transDate)

    {

        RecId calendarRecId;

        FiscalCalendarPeriod fiscalCalendarPeriod;


        calendarRecId = Ledger::fiscalCalendar(CompanyInfo::find().RecId);


        fiscalCalendarPeriod = FiscalCalendarPeriod::findPeriodByCalendarDate(calendarRecId, _transDate, FiscalPeriodType::Operating);


        if (_transDate)

        {

            if (!fiscalCalendarPeriod)

            {

                return checkFailed(strFmt("@SYS17614",date2StrUsr(_transDate, DateFlags::FormatAll)));

            }


            if (fiscalCalendarPeriod.currentLedgerPeriodStatus() != FiscalPeriodStatus::Open)

            {

                return checkFailed(strFmt("@SYS17615", date2StrUsr(_transDate, DateFlags::FormatAll)));

            }

        }


        return true;

    }

24 April 2021

How to get dataSource in DataSource Fileld COC in D365FO

 [ExtensionOf(formdatafieldstr(EntAssetRequestTableCreate, RequestTable, Object))]

final class TRGEntAssetRequestTableCreateFDF_RT_Object_Extension

{

    public void modified()

    {

        FormDataObject dataObject = any2Object(this) as FormDataObject;

        next modified();

        FormDataSource fds = dataObject.dataSource().formRun().dataSource(formDataSourceStr(EntAssetRequestTableCreate, TRGEntAssetRequestObjectTableView));

        fds.executeQuery();

    }

}

22 April 2021

Events get current record in D365FO

 Formrun formRun                          = sender.formRun();

        FormDataSource datasource                = formRun.dataSource(formDataSourceStr(CustInvoiceTemplate,CustInvoiceTemplate));

        CustInvoiceTemplate custInvoiceTemplate       = datasource.cursor();

Service class to get the selected record and deleted matching records and refresh the form data source in D365 F&O

 [DataContractAttribute] class ABCUserProfilesBulkDeleteContract {         UserId userId;     [DataMemberAttribute('UserId')]     pu...