Available and reserved inventory quantities in AX 2012 R3, BP check implementation

As you might already know it is not safe to use inventSum in the code for items that are using warehouse management processes.
For more details you can follow next link: Upgrading code that relies on available and reserved inventory quantities in AX 2012 R3
In short there is replacement table:
Obsolete field/method			Corresponding InventIAvailability method

InventSum.AvailOrdered			InventIAvailability.availTotal()
InventSum.availOrderedCalculated()	InventIAvailability.availTotal()
InventSum.AvailPhysical			InventIAvailability.availPhysical()
InventSum.availPhysicalCalculated()	InventIAvailability.availPhysical()
InventSum.availReservation()		InventIAvailability.availReservation()
InventSum.Ordered			InventIAvailability.ordered()
InventSum.orderedSum()			InventIAvailability.orderedSum()
InventSum.ReservOrdered			InventIAvailability.reservOrdered()
InventSum.ReservPhysical		InventIAvailability.reservPhysical()
For example:
inventSum.ReservPhysical
Should be replaced with:
InventAvailabilityProvider::findByItemIdDim(_itemId, _inventDimCriteria).reservPhysical().parmInventQty()

To be on safe side implement BP check, class to modify SysBPCheckMemberFunction:
Add new method:
/*
    This method checks the source text for calls to InventSum methods that should not be called
    see http://blogs.msdn.com/b/dynamicsaxscm/archive/2014/05/05/upgrading-code-that-relies-on-available-and-reserved-inventory-quantities-in-ax-2012-r3.aspx
*/
protected boolean CheckObsoleteInventSum()
{
    xRefTmpReferences thisRefererences;
    boolean           ret = false;
    Map                 deprecatedFields = new Map(Types::String, Types::String);
    Map                 deprecatedMethods = new Map(Types::String, Types::String);

    deprecatedFields.insert('AvailOrdered', 'InventIAvailability.availTotal()');
    deprecatedFields.insert('AvailPhysical', 'InventIAvailability.availPhysical()');
    deprecatedFields.insert('Ordered', 'InventIAvailability.ordered()');
    deprecatedFields.insert('ReservOrdered', 'InventIAvailability.reservOrdered()');
    deprecatedFields.insert('ReservPhysical', 'InventIAvailability.reservPhysical()');

    deprecatedMethods.insert('availOrderedCalculated','InventIAvailability.availTotal()');
    deprecatedMethods.insert('availPhysicalCalculated','InventIAvailability.availPhysical()');
    deprecatedMethods.insert('availReservation','InventIAvailability.availReservation()');
    deprecatedMethods.insert('orderedSum','InventIAvailability.orderedSum()');


    // check if things are used, that are being superseed by something new
    thisRefererences.setTmpData(tmpxRefReferences);
    while select thisRefererences
        where thisRefererences.ParentName == 'InventSum'
        &&   (thisRefererences.Kind == xRefKind::TableInstanceMethod ||
               thisRefererences.Kind == xRefKind::TableField)
    {
        switch (thisRefererences.Kind)
        {
            case xRefKind::TableInstanceMethod:
                if ( deprecatedMethods.exists(thisRefererences.name) )
                {
                    ret = true;
                    sysBPCheck.addError(#BPErrorMethodDiscontinuedInLaterVers, thisRefererences.Line, thisRefererences.Column, strFmt("@SYS68910", thisRefererences.ParentName,
                                       (thisRefererences.Kind == xRefKind::ClassInstanceMethod || thisRefererences.Kind == xRefKind::TableInstanceMethod || thisRefererences.Kind == xRefKind::MapInstanceMethod) ? '.' : '::',
                                        thisRefererences.Name, deprecatedMethods.lookup(thisRefererences.name)));
                    break;
                }
            case xRefKind::TableField:
                if ( deprecatedFields.exists(thisRefererences.name) )
                {
                    ret = true;
                    sysBPCheck.addError(#BPErrorMethodDiscontinuedInLaterVers, thisRefererences.Line, thisRefererences.Column, strFmt("@SYS68910", thisRefererences.ParentName,
                                       '.',
                                        thisRefererences.Name, deprecatedFields.lookup(thisRefererences.name)));
                    break;
                }
        }
    }
    return ret;
}
Modify \Classes\SysBPCheckMemberFunction\check and add to the end:
this.CheckObsoleteInventSum();

Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags