24 March 2022

COC ,Access to another data source from data source method on form

  FormDataSource     salesLine_ds = this.formRun().dataSource(formDataSourceStr(SalesTable, salesLine));

        SalesLine salesLine = salesLine_ds.cursor();

29 January 2022

How to get sales order delivery postal address Phone ,street in D365FO

 LogisticsPostalAddress deliveryPostalAddress = LogisticsPostalAddress::findRecId(salesTable.DeliveryPostalAddress);

deliveryPostalAddress.City;                   

 deliveryPostalAddress.State;

            

10 January 2022

How to get product variants in D365FO using X++

  public EcoResProductDisplayProductNumber getProductVariants(SalesLine _saleLine)

    {

        InventDimCombination            inventDimCombination  = InventDimCombination::findVariantId(_saleLine.RetailVariantId);

        InventDim                       inventDim;

        InventDistinctProductExpanded   inventDistinctProductExpanded;


        select inventDistinctProductExpanded

            where inventDistinctProductExpanded.ItemId == _saleLine.ItemId

            && inventDistinctProductExpanded.InventDimId == inventDimCombination.InventDimId;


        return inventDistinctProductExpanded.DisplayProductNumber;

    }

26 November 2021

Try catch exception example in D365FO

 class TestClass

{

    public static void main(Args args)

    {

        PurchTable purchTable;

        

        System.Exception ex;

        

            //Counter cnt = 1;

            while select purchTable

            {

                try

                {

                    //doing updation on  the purchatable.

                }


                catch(ex)

                {

                    System.String messageEx = ex.Message;

                    warning(strFmt("There is an error%1",messageEx));                    

                }

            }

        

       

    }


}

21 November 2021

ED365FO event handler to get current database record

   public static void TRGvalidateHours(FormControl sender, int controlName)

    {

        FormRealControl  control = sender as FormRealControl;

        FormRun     formRun = sender.formRun();

        FormStringControl projIdControl = formRun.design().controlName(formControlStr(TSTimesheetEntry,ProjId));

        

        FormDataSource TSTimeSheetLineWeek_ds  = formRun.dataSource(formDataSourceStr(TSTimesheetEntry,TSTimesheetLineWeek)) as FormDataSource;

        TSTimesheetLineWeek timesheetLineWeek = TSTimeSheetLineWeek_ds.cursor();

        TSTimesheetTable    timeSheetTable = TSTimesheetTable::find(timesheetLineWeek.TimesheetNbr);

        ProjTable           projTable = ProjTable::find(projIdControl.text());

}

14 November 2021

Exception handling in D365 FO - Capture the exception

System.Exception        ex;

 try

{

    // total logic

 }

            catch(ex)

            {

                System.String messageEx = ex.Message;

                info(strFmt("Exception: %1",messageEx));

            }

            catch (Exception::CLRError)

            {

                ex = CLRInterop::getLastException().GetBaseException();

                error(ex.get_Message());

            }

25 October 2021

D365FO disposable context class example

Reference Standard Class:AssetProposalDepreciationContext

Scenario
: Payment journal Customer receipt data is not getting.

Below is the route cause: the temp table record is getting cleared.

To fix issue implemented the disposable context concept.

New class :

class CITPaymProposalReportContext implements System.IDisposable
{
    static CITPaymProposalReportContext instance;
    public CustVendPaymProposalTmp vendPaymProposalTemp;

    public void new()
    {
        if (instance)
        {
            throw Error ("Nesting of CITPaymProposalReportContext is not supported.");
        }
        instance = this;
    }

    public void dispose()
    {
        instance = null;
    }

    static public CITPaymProposalReportContext current()
    {
        return instance;
    }

}


Before clearing the record to get it and keep it in global variable using context class so need to create extension for the "CustVendPaymProposalTmp" table insert() method.

[ExtensionOf(TableStr(CustVendPaymProposalTmp))]
final class CITCustVendPaymProposalTmp_TBL_Extension
{
    public void insert()
    {
        using (CITPaymProposalReportContext context = new CITPaymProposalReportContext())
        {
            next insert();
            context.vendPaymProposalTemp = this;
        }

    }

}

Create another extension- Post COC - "PaymentProposalReport" insert payment method and get the record and assign to variable.

[ExtensionOf(classStr(PaymProposalReport))]
final class CITPaymProposalReportClass_Extension
{

  protected void insertPayment(CustVendPaymProposalTmp _custVendPaymProposalTmp)
    {
        
        LedgerJournalTrans ledgerJournalTrans;
        CustVendPDCRegister custVendPDCRegister;
        
        next insertPayment(_custVendPaymProposalTmp);

        CITPaymProposalReportContext context = CITPaymProposalReportContext::current();
        if (context && context.vendPaymProposalTemp)
        {
            _custVendPaymProposalTmp = context.vendPaymProposalTemp;
        }
        
        select ledgerJournalTrans
                        where ledgerJournalTrans.RecId == _custVendPaymProposalTmp.WLKLedgerJournalTransRecId;
        
        if(ledgerJournalTrans)
        {
            _custVendPaymProposalTmp.WLKAmountInTxt = Global::numeralsToTxt(abs(_custVendPaymProposalTmp.PaymentAmountMST));
            _custVendPaymProposalTmp.WLKTxt = ledgerJournalTrans.Txt;
            _custVendPaymProposalTmp.WLKUserId = ledgerJournalTrans.ledgerJournalTable().createdBy;

            select custVendPDCRegister
                        where custVendPDCRegister.LedgerJournalTrans == ledgerJournalTrans.RecId;

            _custVendPaymProposalTmp.PaymReference = ledgerJournalTrans.BankCentralBankPurposeText;
            _custVendPaymProposalTmp.WLKCheckNumber = ledgerJournalTrans.DocumentNum;
            _custVendPaymProposalTmp.BankAccountTableName = ledgerJournalTrans.offsetAccountName();
            _custVendPaymProposalTmp.WLKMaturityDate = ledgerJournalTrans.DocumentDate;
            _custVendPaymProposalTmp.ttsbegin();
            _custVendPaymProposalTmp.selectForUpdate(true);
            _custVendPaymProposalTmp.update();
            _custVendPaymProposalTmp.ttscommit();
            PaymProposalReport::insertCustSettlementTmp(_custVendPaymProposalTmp);
        }
    }
}

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