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

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);
        }
    }
}

02 July 2021

D365 postman Error: Maximum response size reached

 

My requests take longer time to receive response


ResponseSize.png

In the latest version v7.3.5, the response time is longer and status code displays earlier than the response, as it relatively takes a longer time to load large responses on the application. We also have a limit of 50mb response that can be safely viewed. By default, we do not load response larger than 50mb. But if it extends, 100 MB is maximum buffer we currently have, so you can still change the response size up to 100 by navigating to Settings > General Tab > Max response size in MB.

MaxResponseSize.png

If your response exceeds 100+ MB, it is probably not going to succeed. But as a workaround, you can try the "Send and Download" option when running the request which should help you.

D365FO Odata - d365 postman please verify that the user is valid and set up correctly

 {

    "Message""Please verify that the user is valid and set up correctly."
}

Sol:

System Administration > Setup > Azure Active Directory Applications

Click the +New button to add a new registration.  

Grab the Application ID from the registration in the Azure Portal and insert it into the Client ID field.

Fill out the rest of the fields as necessary.

How to add the Display method in the form level in D365 F&O

 The below examle is to add the form -Data source level adding display method and assigning to form design control.