Skip to main content

Notifications

Supply Chain Management forum
Unanswered

In Critical on hand inventory report want to add maximum quantity same as minimum

Posted on by 1,751
Hi Experts,
 
I want to add maximum quantity in critical on hand inventory report. Difficulty is where I should put code and what in class InventSumCriticalInt and how to add my new report to user interface(subcribe new report design).
 
 
Thanks,
Faiz
 
 
  • faiz7049 Profile Picture
    faiz7049 1,751 on at
    In Critical on hand inventory report want to add maximum quantity same as minimum
    Hi Experts,
     
    Please could you check my below extension code. What is missing in it.
     
    [ExtensionOf(classStr(InventSumCriticalInit))]
    
    final public class SFA_InventSumCriticalInit_Extension
    {
    
                public void processInventSumCriticalRecords()
            {
                next processInventSumCriticalRecords();
            
                QueryRun queryRun = new QueryRun(this.criticalOnHandQuery);
                ReqItemTable reqItemTable;
                InventDim inventDim;
                ItemId itemId;
                InventDimParm inventDimParm;
                InventDimGroupSetup inventDimGroupSetup;
                ReqSetup reqSetup;
    
                while (queryRun.next())
                {
                    if (queryRun.changed(tableNum(ReqItemTable)))
                    {
                        reqItemTable = queryRun.get(tableNum(ReqItemTable));
                        if (itemId != reqItemTable.ItemId)
                        {
                            itemId = reqItemTable.ItemId;
    
                            reqSetup = ReqSetup::newItemId(itemId);
                            inventDimGroupSetup = InventDimGroupSetup::newItemId(itemId);
                            inventDimParm.initCovPrDimension(inventDimGroupSetup);
                        }
                    }
    
                    inventDim = queryRun.get(tableNum(InventDim));
    
                    // Custom logic to include maximum quantity
                    this.insertPhysicalOnhandBelowMinimumQuantity_Extended(
                    reqSetup,
                    itemId,
                    inventDim,
                    inventDimParm,
                    inventDimGroupSetup);
                }
            }
    
            private void insertPhysicalOnhandBelowMinimumQuantity_Extended(
            ReqSetup _reqSetup,
            ItemId _itemId,
            InventDim _inventDim,
            InventDimParm _inventDimParm,
            InventDimGroupSetup _inventDimGroupSetup)
            {
               InventDim inventDimCoverage = InventDim::find(_inventDim.reqCovDimId(_inventDimGroupSetup));
               
                InventQtyMaxOnhand maximumOnHandQuantity = ReqSetupDim::newCovInventDimId(_reqSetup, inventDimCoverage.InventDimId).maxInventOnHand(); // Fetch max quantity
                  
                    this.initTmpTable_Extended(maximumOnHandQuantity);
                    this.insertTmpTable();
             }
    
            protected void initTmpTable_Extended(InventQtyMaxOnhand _maximumOnHandQuantity) // Add max quantity parameter
            {
              
              
                inventSumCriticalTmp.QtyMaxOnhand = _maximumOnHandQuantity; // Store max quantity
              
            }
    
    }
     
  • faiz7049 Profile Picture
    faiz7049 1,751 on at
    In Critical on hand inventory report want to add maximum quantity same as minimum
    Hi Experts,

    Maximum quantity is not showing in Critical on hand inventory report. Could you please help my extension code.
     


    ​​​​​​​
  • faiz7049 Profile Picture
    faiz7049 1,751 on at
    In Critical on hand inventory report want to add maximum quantity same as minimum
    Hi Experts,
     
    Could you please check my approach is correct in below X++ code.
     
    [ExtensionOf(classStr(InventSumCriticalInit))]
    
    final public class SFA_InventSumCriticalInit_Extension
    {
    
            public void processInventSumCriticalRecords()
            {
                next processInventSumCriticalRecords();
            
                QueryRun queryRun = new QueryRun(this.criticalOnHandQuery);
                ReqItemTable reqItemTable;
                InventDim inventDim;
                ItemId itemId;
                InventDimParm inventDimParm;
                InventDimGroupSetup inventDimGroupSetup;
                ReqSetup reqSetup;
    
                while (queryRun.next())
                {
                    if (queryRun.changed(tableNum(ReqItemTable)))
                    {
                        reqItemTable = queryRun.get(tableNum(ReqItemTable));
                        if (itemId != reqItemTable.ItemId)
                        {
                            itemId = reqItemTable.ItemId;
    
                            reqSetup = ReqSetup::newItemId(itemId);
                            inventDimGroupSetup = InventDimGroupSetup::newItemId(itemId);
                            inventDimParm.initCovPrDimension(inventDimGroupSetup);
                        }
                    }
    
                    inventDim = queryRun.get(tableNum(InventDim));
    
                    // Custom logic to include maximum quantity
                    this.insertPhysicalOnhandBelowMinimumQuantity_Extended(
                    reqSetup,
                    itemId,
                    inventDim,
                    inventDimParm,
                    inventDimGroupSetup);
                }
            }
    
            private void insertPhysicalOnhandBelowMinimumQuantity_Extended(
            ReqSetup _reqSetup,
            ItemId _itemId,
            InventDim _inventDim,
            InventDimParm _inventDimParm,
            InventDimGroupSetup _inventDimGroupSetup)
            {
                InventDim inventDimCoverage = InventDim::find(_inventDim.reqCovDimId(_inventDimGroupSetup));
                InventQtyMinOnhand minimumOnHandQuantity = ReqSetupDim::newCovInventDimId(_reqSetup, inventDimCoverage.InventDimId).minInventOnHand();
                InventQtyMaxOnhand maximumOnHandQuantity = ReqSetupDim::newCovInventDimId(_reqSetup, inventDimCoverage.InventDimId).maxInventOnHand(); // Fetch max quantity
    
                InventSum inventSumOnHand  = InventOnHandQty::newItemDim(_itemId, inventDimCoverage, _inventDimParm).inventSum();
    
                if (inventSumOnHand.physicalInventCalculated() < minimumOnHandQuantity)
                {
                    this.initTmpTable_Extended(inventSumOnHand, _inventDim, minimumOnHandQuantity, maximumOnHandQuantity);
                    this.insertTmpTable();
                }
            }
    
            protected void initTmpTable_Extended(
            InventSum _inventSumOnHand,
            InventDim _inventDim,
            InventQtyMinOnhand _minimumOnHandQuantity,
            InventQtyMaxOnhand _maximumOnHandQuantity) // Add max quantity parameter
            {
                InventIAvailability inventAvailability = InventAvailabilityProvider::findBySumDim(_inventSumOnHand, _inventDim).parmInventAvailability();
                inventSumCriticalTmp.QtyMinOnhand = _minimumOnHandQuantity;
                inventSumCriticalTmp.QtyMaxOnhand = _maximumOnHandQuantity; // Store max quantity
                inventSumCriticalTmp.ItemId = _inventSumOnHand.ItemId;
                inventSumCriticalTmp.InventDimFieldsMap::initAllDimensionsFrom(_inventDim);
                inventSumCriticalTmp.Ordered = inventAvailability.ordered();
                inventSumCriticalTmp.ItemName = _inventSumOnHand.itemName();
                inventSumCriticalTmp.PhysicalInvent = _inventSumOnHand.physicalInventCalculated();
            }
        }
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,888 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,247 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans