Skip to main content
Solved

Add a calculated field to SO Lines?


Denham
Jr Varsity II
Forum|alt.badge.img

Hello

I am trying to add a custom field to the SO Line details, which will calculate Available Qty - Line Qty for each line on the sales order.

We are trying to do this as we have orders which we import that contain thousands of lines, and after importing it is extremely tedious to scroll through to find the lines which have the “QTY will go negative” error tagged on them. We do not allow inventory to go negative in our system, and for our use case, we must put the “oversold” quantity of product onto separate orders.

I dont know where to start with this, and any help will be greatly appreciated!

Best answer by Naveen Boga

Hi @Denham  We can do this with minor customization and please find the steps below for reference.

  1. Extend the SOLine DAC file, and introduce a new calculated field (Decimal type)
  2. Extend the SOOrderEntry Graph file
  3. Write a fieldselecting event, and inside this event, add logic to get the Qty available for this field and subtract with the line order qty. 

Hope this helps and let me know if you need any assistance.

View original
Did this topic help you find an answer to your question?

7 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3393 replies
  • Answer
  • May 20, 2023

Hi @Denham  We can do this with minor customization and please find the steps below for reference.

  1. Extend the SOLine DAC file, and introduce a new calculated field (Decimal type)
  2. Extend the SOOrderEntry Graph file
  3. Write a fieldselecting event, and inside this event, add logic to get the Qty available for this field and subtract with the line order qty. 

Hope this helps and let me know if you need any assistance.


Denham
Jr Varsity II
Forum|alt.badge.img
  • Author
  • 29 replies
  • May 22, 2023

Hi @Naveen Boga

Thank you for the quick response and explanation! 

Would you possibly be able to help me write the fieldselecting event. I am not the most experienced with writing customizations so far, but I am working on learning. Or if you could point me in the right direction as to where I can read up more on how to do this, that would be great!

Thank you


Denham
Jr Varsity II
Forum|alt.badge.img
  • Author
  • 29 replies
  • May 22, 2023

With some help from ChatGPT, I managed to get the code below to validate and published. The problem now is that the calculation is not correct. For example on an order with a line with a quantity of 901pcs, and 902pcs are available, the Remaining Qty column is showing 901pcs.

 

   // Field-Selecting event handler for the OrderQty field on the SOLine DAC
protected virtual void SOLine_OrderQty_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
    if (e.Row == null)
        return;

    SOLine line = (SOLine)e.Row;

    if (line.InventoryID != null && line.SiteID != null)
    {
        // Retrieve the Inventory Site Status record
        INSiteStatus siteStatus = PXSelect<INSiteStatus,
            Where<INSiteStatus.inventoryID, Equal<Required<INSiteStatus.inventoryID>>,
                And<INSiteStatus.siteID, Equal<Required<INSiteStatus.siteID>>>>>
            .Select(Base, line.InventoryID, line.SiteID);

        if (siteStatus != null)
        {
            // Calculate the Quantity Available by subtracting the Ordered and Shipped quantities
            decimal qtyAvailable = (siteStatus.QtyAvail.GetValueOrDefault() - siteStatus.QtySOShipping.GetValueOrDefault());
            decimal orderQty = line.OrderQty.GetValueOrDefault();
            decimal qtyRemaining = qtyAvailable - orderQty;

            // Set the calculated remaining quantity to the UsrQtyRemaining field in the SOLineQtyRemaining DAC extension
            SOLineQtyRemaining lineExt = PXCache<SOLine>.GetExtension<SOLineQtyRemaining>(line);
            lineExt.UsrQtyRemaining = qtyRemaining;

            // Set the calculated remaining quantity as the return value for the field-selecting event
            e.ReturnValue = qtyRemaining;
        }
    }
}

#endregion
  }
}

 


Denham
Jr Varsity II
Forum|alt.badge.img
  • Author
  • 29 replies
  • May 22, 2023

Figured out the issue. The code was over-writing the order qty due to the final ReturnValue portion.

Going to do a few more tests, but I think I got it figured out!

Thank you @Naveen Boga for pointing me in the right direction

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3393 replies
  • May 22, 2023

Hi @Denham  Great! Thanks for sharing the update.

Let me know if you need any help.


  • Freshman I
  • 3 replies
  • March 19, 2024

Can you explain the purpose or intended use of the calculated field to be added to SO Lines?


Denham
Jr Varsity II
Forum|alt.badge.img
  • Author
  • 29 replies
  • March 19, 2024
Kathlyn wrote:

Can you explain the purpose or intended use of the calculated field to be added to SO Lines?

Hi Kathlyn

In this case, we are using this field to tell us the remaining quantity of an inventory item after the sales order is fulfilled(Qty Available - Line Qty). We have some items which are extremely fast movers, that are also very difficult to acquire stock. So we are using this field to reduce quantity on orders as we see fit, depending on the amount of stock that will remain after the order is fulfilled.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings