Tuesday, June 21, 2022

How to get messages from Infolog through x++ in Dynamics 365 FO


Error Handling is one of the very good practices to used especially when we are using integration of Dynamics 365 Fin Ops with other applications.


When we encounter these errors in an infolog the best way to get those error messages is through two most important classes : - 


SysInfologEnumerator  

SysInfoLogMessageStruct


Lets see throw below code snippet how these classes help us to achieve our goal : - 



class GetInfologMessages
{
    public static str getErrorStr()
    {
        SysInfologEnumerator         enumerator;

        SysInfologMessageStruct     msgStruct;

        Exception                              exception;

        str                                          error;   

        enumerator      =   SysInfologEnumerator::newData(infolog.copy(1,infolog.num()));

        while(enumerator.moveNext())
        {
            msgStruct   =   new SysInfologMessageStruct(enumerator.currentMessage());

            exception   =   enumerator.currentException();

            error       =   strfmt("%1 %2", error, msgStruct.message());
        }

        return error;
    }

    public static utcdatetime getErrorDatetime()
    {

        SysInfologEnumerator        enumerator;

        SysInfologMessageStruct     msgStruct;

        Exception                   exception;

        str                         errormsg;

        utcdatetime                 errordatetime;

        enumerator      =   SysInfologEnumerator::newData(infolog.copy(1,infolog.num()));

        while (enumerator.moveNext())
        {
            msgStruct   =   new SysInfologMessageStruct(enumerator.currentMessage());

            exception   =   enumerator.currentException();

            errormsg       =   strfmt("%1 %2", errormsg, msgStruct.message());
        }

        if(errormsg!='')
        {
            errordatetime = DateTimeUtil::getSystemDateTime();
        }

        return errordatetime;
    }
}


That's all for now. Please let us know your questions or feedback in comments section !!!!

Monday, June 6, 2022

How to call an external web link through x++ in Dynamics 365 Fin Ops

 

Calling an external web link is very easy to implement. Sometimes we get this requirement to redirect user to a website based on customer's requirements.

We can easily do that using Browser class.


Here is the code mentioned below : - 


public static void main(Args _args)
{
    Browser browser = new Browser();

    browser.navigate('www.google.com', true, false);
}


That's all for now. Please let us know your questions or feedback in comments section !!!!

How to calculate total discount for a purchase order through X++ in Dynamics 365 Fin Ops

 

Most of the times consultants get a requirement to calculate the discount for the supply chain documents such as Purchase Orders and Sales Orders.

The key to do this calculation is to use PurchTotals class.

Here is the code mentioned below where we are calculating the discount for a purchase order : - 



class CalculateTotalsOfPurchaseOrder
{
    public static void main(Args _args)
    {
        PurchTotals purchTotals;

        PurchTable  purchTable  = PurchTable::find('PO012345');

        AmountCur   totalAmount;

        purchTotals = PurchTotals::newPurchTable(purchTable);

        purchTotals.calc();

        totalAmount = purchTotals.purchTotalAmount();

        info(strFmt('Purchase order: %1 - Total value: %2', purchTable.PurchId, totalAmount));
    }
}


That's all for now. Please let us know your questions or feedback in comments section !!!!

How to reverse Free Text Invoice Voucher entries without Dialog

 Hey Folks ,  This blog post is in continuation of the previous post for Reversing Free Text Invoice Voucher entries with Dialog. Only diffe...