Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

Help me fix this error on the processing screen : Error: An error occurred during…

  1. User

    Help me fix this error on the processing screen : Error: An error occurred during processing of the field Estimated Quantity value 0 The specified estimated quantity 0.0000 is less than the sum of the estimated quantities of all lines 1.0000 in the associated appointment(s). . Here is the customization code that I had used : using System; using System.Collections.Generic; using PX.Data; using PX.Data.BQL; using PX.Data.BQL.Fluent; using PX.Objects.FS;

    namespace ServiceOrders { public class SOForceCompleteProcess : PXGraph { public PXCancel Cancel;

        public SelectFrom<FSServiceOrder>
            .Where<FSServiceOrder.status.IsEqual<AwaitingStatus>>
            .ProcessingView Orders;
    
        public SOForceCompleteProcess()
        {
            Orders.SetProcessCaption("Reopen & Deallocate");
            Orders.SetProcessAllCaption("Reopen & Deallocate All");
            Orders.SetProcessDelegate(ProcessOrders);
        }
    
        public static void ProcessOrders(List<FSServiceOrder> list)
        {
            var graph = PXGraph.CreateInstance<ServiceOrderEntry>();
    
            foreach (var order in list)
            {
                try
                {
                    graph.Clear();
                    graph.ServiceOrderRecords.Current =
                        graph.ServiceOrderRecords.Search<FSServiceOrder.refNbr>(
                            order.RefNbr, order.SrvOrdType);
    
                    if (graph.ServiceOrderRecords.Current?.Status == "W")
                    {
                        var current = graph.ServiceOrderRecords.Current;
    
                        // Step 1: Set order status to Open
                        current.Status = "O";
                        current.Completed = false;
                        current.OpenDoc = true;
                        graph.ServiceOrderRecords.Cache.SetValueExt<FSServiceOrder.hold>(current, false);
                        graph.ServiceOrderRecords.Update(current);
    
                        // Step 2: Reset line status & deallocate inventory
                        foreach (FSSODet line in PXSelect<FSSODet,
                            Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
                                  And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
                            .Select(graph, current.SOID))
                        {
                            if (line.Status == "Completed")
                            {
                                line.Status = "Open";
                                graph.Caches<FSSODet>().Update(line);
                            }
    
                            if (line.Qty > 0)
                            {
                                // Find and update associated appointment lines
                                foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                                    Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                                    .Select(graph, line.SODetID))
                                {
                                    if (apptLine.EstimatedQty > 0)
                                    {
                                        apptLine.EstimatedQty = 0; // Set appointment quantity to 0
                                        graph.Caches<FSAppointmentDet>().Update(apptLine);
                                    }
                                }
    
                                // Now set the service order line quantity to 0
                                line.Qty = 0;
                                graph.Caches<FSSODet>().Update(line);
                            }
                        }
    
                        // Step 3: Mark order as Completed again
                        current.Status = "C";
                        current.Completed = true;
                        current.OpenDoc = false;
                        graph.ServiceOrderRecords.Update(current);
    
                        graph.Save.Press();
    
                        PXProcessing<FSServiceOrder>.SetInfo($"Order {current.RefNbr} reopened, inventory deallocated, and marked as completed.");
                    }
                }
                catch (Exception ex)
                {
                    PXProcessing<FSServiceOrder>.SetError(ex);
                }
            }
        }
    
        public class AwaitingStatus : BqlString.Constant<AwaitingStatus>
        {
            public AwaitingStatus() : base("W") { }
        }
    }
    

    }. I am trying to achieve the deallocation of inventory items from service orders, so that they can be cleared from the inventory allocation details page in Acumatica.

  2. Assistant

    The error you are encountering:

    Error: An error occurred during processing of the field Estimated Quantity value 0 The specified estimated quantity 0.0000 is less than the sum of the estimated quantities of all lines 1.0000 in the associated appointment(s).
    

    occurs because you are setting the appointment lines' EstimatedQty to 0 before updating the parent service order lines, which causes a mismatch: the system expects the service order line's estimated quantity to be at least as much as the sum of related appointment lines' estimated quantities.


    Why this happens

    In Acumatica's Field Service module, the EstimatedQty on appointment lines (FSAppointmentDet) must be consistent with the Qty (quantity) of the corresponding service order line (FSSODet). If an appointment line's EstimatedQty is greater than the Qty of the service order line, you get this error.

    Your code is:

    • Setting appointment lines' EstimatedQty to zero
    • Then setting service order line's Qty to zero

    But the underlying system logic may re-validate these quantities (or you could have other linked data), causing the error. Sometimes, the order should be the inverse, or you may need to recalculate / refresh the relevant caches and persist changes progressively.


    Proposed Fixes

    1. Update the service order line quantity first (set Qty = 0) before updating the appointment line estimated quantities. This way, appointment lines have zero to compare against, avoiding the inconsistency.

    2. Ensure you call graph.Save.Press() after these changes to persist them and avoid cache inconsistencies.

    3. It's a good idea to call graph.Caches<T>().Persist() after making changes, especially if you perform multiple cache updates.

    4. Refresh the caches or skip validation if possible (sometimes done by setting flags), but this depends on the base system behavior.


    Modified snippet of your foreach loop

    foreach (FSSODet line in PXSelect<FSSODet,
        Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
              And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
        .Select(graph, current.SOID))
    {
        if (line.Status == "Completed")
        {
            line.Status = "Open";
            graph.Caches<FSSODet>().Update(line);
        }
    
        if (line.Qty > 0)
        {
            // First, set the service order line quantity to 0
            line.Qty = 0;
            graph.Caches<FSSODet>().Update(line);
    
            graph.Save.Press(); // Persist changes before updating appointment lines
    
            // Then update associated appointment lines to zero
            foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                .Select(graph, line.SODetID))
            {
                if (apptLine.EstimatedQty > 0)
                {
                    apptLine.EstimatedQty = 0; // Set appointment quantity to 0
                    graph.Caches<FSAppointmentDet>().Update(apptLine);
                }
            }
    
            graph.Save.Press(); // Persist appointment line changes
        }
    }
    

    Explanation:

    • By updating and saving the service order line first, the system knows the line quantity is 0.
    • Then updating appointment lines to 0 estimated quantity becomes valid.
    • Calling graph.Save.Press() after each ensures the cache is clean and validations are correct.

    Additional notes

    If you want better performance and fewer saves:

    • You can try updating all lines' quantities first; then update all appointment lines and save once. But you must ensure caches and state are valid, which sometimes is tricky due to validations.

    Summary

    The primary cause is the order in which you update service order lines and appointment lines. Fix it by updating the service order line Qty to zero before setting appointment lines' EstimatedQty to zero, and persist changes appropriately.


    If you want, I can help you refactor the entire code with these fixes. Let me know!

  3. User

    Ref. Nbr. Inventory ID Line Status Line Type Mark for PO Billing Rule Description Last Reference SONumber Equipment Action Target Equipment ID Model Equipment Ref. Nbr. Component ID Component Ref. Nbr. Staff Member ID Warranty Warehouse Location UOM Estimated Duration Estimated Quantity Unit Price Manual Price Unit Cost Estimated Amount Service Contract Item Covered Quantity Overage Quantity Overage Unit Price Appointment Estimated Duration Appointment Duration Appointment Quantity Appointment Amount Appointment Count Billable Quantity Ext. Price Discount Percent Discount Amount Amount Usr Mark SO SOStatus Vendor ID Vendor Location ID PO Nbr. PO Status Tax Category Account Equipment Action Comment Line Nbr. PO Completed Prepaid Item Service Order Nbr. Service Order Type Sort Order Subaccount Branch Project Task Free Item Ext. Cost PO Source Usrstatus Manual Discount 0001 ONLINE SERVICE Completed Service False Time Online Services - Telephonic and Email support via the Help Desk 018163-1 N/A 000064 False BASEMENT DEFAULT PC 1 h 00 m 1.0000 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 1 h 00 m 12 h 32 m 12.5333 0.00 1 True 1.0000 0.00 0.000000 0.0000 0.00 TAXABLE 40000 1 False False 018163 MRO 1 000-000-000 MAIN False 0.00 True 0002 TAGEQ STATUS Completed Service False Time Target Equipment Status before repair 018163-2 N/A 000064 False BASEMENT DEFAULT PC 1 h 00 m 1.0000 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 1 h 00 m 9 h 29 m 9.4833 0.00 1 True 1.0000 0.00 0.000000 0.0000 0.00 TAXABLE 40000 2 False False 018163 MRO 2 000-000-000 MAIN False 0.00 True 0003 BRK SERV Completed Service False Time Breakdown Service 018163-4 N/A 000064 False BASEMENT DEFAULT PC 1 h 00 m 1.0000 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 1 h 01 m 17 h 29 m 17.4833 0.00 2 True 1.0000 0.00 0.000000 0.0000 0.00 TAXABLE 40000 3 False False 018163 MRO 3 000-000-000 MAIN False 0.00 True 0004 TRAVEL Completed Service False Time Appointment Travel 018163-3 N/A False SERVICE DEFAULT PC 0 h 01 m 0.0167 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 0 h 01 m 1 h 08 m 1.1333 0.00 1 True 0.0167 0.00 0.000000 0.0000 0.00 TAXABLE 40000 4 False False 018163 MRO 4 000-000-000 MAIN False 0.00 True 0005 TRAVEL Completed Service False Time Appointment Travel 018163-3 N/A False SERVICE DEFAULT PC 0 h 01 m 0.0167 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 0 h 01 m 1 h 44 m 1.7333 0.00 1 True 0.0167 0.00 0.000000 0.0000 0.00 TAXABLE 40000 5 False False 018163 MRO 5 000-000-000 MAIN False 0.00 True 0006 11996908001 Completed Inventory Item False Flat Rate Spare, Sipper Probe Assy S1C, Roche # 11996908001 018163-3 SM002200 N/A 000064 False BASEMENT DEFAULT PC 0 h 00 m 1.0000 0.0000 False 52,792.3300 0.00 False 0.0000 0.0000 0 h 00 m 0 h 00 m 1.0000 0.00 1 True 1.0000 0.00 0.000000 0.0000 0.00 True TAXABLE 40000 6 False False 018163 MRO 6 000-000-000 MAIN False 52,792.33 True 0007 05151643001 Completed Inventory Item False Flat Rate Measuring Cell With Ref. Elect V7.0, Roche 018163-3 SM002203 N/A 000064 False BASEMENT DEFAULT PC 0 h 00 m 1.0000 0.0000 False 173,529.9829 0.00 False 0.0000 0.0000 0 h 00 m 0 h 00 m 1.0000 0.00 1 True 1.0000 0.00 0.000000 0.0000 0.00 True TAXABLE 40000 7 False False 018163 MRO 7 000-000-000 MAIN False 173,529.98 True 0008 TRAVEL Completed Service False Time Appointment Travel 018163-4 N/A False SERVICE DEFAULT PC 0 h 01 m 0.0167 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 0 h 01 m 2 h 15 m 2.2500 0.00 1 True 0.0167 0.00 0.000000 0.0000 0.00 TAXABLE 40000 8 False False 018163 MRO 8 000-000-000 MAIN False 0.00 True 0009 TRAVEL Completed Service False Time Appointment Travel 018163-4 N/A False SERVICE DEFAULT PC 0 h 01 m 0.0167 0.0000 False 0.0000 0.00 False 0.0000 0.0000 0.0000 0 h 01 m 0 h 07 m 0.1167 0.00 1 True 0.0167 0.00 0.000000 0.0000 0.00 TAXABLE 40000 9 False False 018163 MRO 9 000-000-000 MAIN False 0.00 True Read the excel , and tell me why i am still getting the same error as before

  4. Assistant

    Thanks for sharing the service order lines data. From your data and error message:

    "The specified estimated quantity 0.0000 is less than the sum of the estimated quantities of all lines 1.0000 in the associated appointment(s)."


    What this means

    • Your service order lines (FSSODet) have Estimated Quantity = 0
    • But there exist one or more related appointment lines (FSAppointmentDet) with EstimatedQty > 0 (sum total is 1.0000)

    This breaks the system rule:
    EstimatedQty of the service order line must be equal or greater than the sum of EstimatedQty of appointment lines referencing it.


    What your data shows

    Let’s look at the key parts from the data for some lines of Inventory Item line type (lines #6, #7) and service lines types:

    • Inventory Items lines have Estimated Quantity = 1.0000, but Unit Price = 0.0000 (likely a formatting issue?) but ok.

    • Appointment Quantity columns (Appointment Quantity in your export) show values like:

      For example, Line #6 (Inventory Item): Appointment Quantity = 1.0000
      Line #7 (Inventory Item): Appointment Quantity = 1.0000

    • The problem is with the Estimated Quantity on the service order lines: it's zero, while related appointment lines seem to still have EstimatedQty > 0.


    What your code is doing vs. what's happening on the actual data

    Your code attempts to:

    1. Set appointment lines' EstimatedQty = 0
    2. Then set service order lines' Qty = 0

    But from your error and data, it looks like:

    • The appointment lines' estimated quantities still have positive values not zeroed, causing the validation failure.

    Possible causes:

    1. The code isn't successfully setting the appointment lines' EstimatedQty to zero

      • Maybe the selection Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>> isn’t catching all appointment lines
      • Or the caches are not being saved properly after updating appointment lines.
    2. The service order line's estimated quantity property (EstimatedQty) might be different from Qty

      • You are setting line.Qty = 0, but the error refers to Estimated Quantity value 0, which suggests that the field controlling the estimated qty on the service order line might be a different field than Qty.
    3. The status of lines

      • Lines are marked Completed. Sometimes updating completed lines requires more careful handling (like uncompleting then updating qty).
    4. There could be other related appointment data not addressed by your code

      • E.g., other linked appointment details that are not cleared.

    What to check and fix

    1. Confirm you update the EstimatedQty on appointment lines and persist changes

    In your code:

    apptLine.EstimatedQty = 0;
    graph.Caches<FSAppointmentDet>().Update(apptLine);
    

    But are you persisting? Call graph.Save.Press() or at least graph.Caches<FSAppointmentDet>().Persist(PXDBOperation.Update) after updating, before updating service order lines to zero.


    2. Confirm which fields to update on the service order line

    • The error complains about Estimated Quantity (likely the field: FSSODet.EstimatedQty), but your code updates only line.Qty = 0.

    • Is EstimatedQty a separate field from Qty?

    In Acumatica FS, EstimatedQty is often a separate field representing the quantity estimated/planned for the service.

    So you must update line.EstimatedQty along with line.Qty.


    Try:

    line.EstimatedQty = 0;
    line.Qty = 0;
    graph.Caches<FSSODet>().Update(line);
    

    3. Confirm cache updates and graph saves are in correct order

    Do this after updating lines and appointment lines, something like:

    • Update all service order lines (zero Qty and EstimatedQty)
    • Save changes
    • Update appointment lines' EstimatedQty to zero
    • Save again

    Or do vice versa but save after each step.


    4. Check for any Approval/Status constraints

    • Appointments may be linked and approved or closed, and may not allow quantity changes freely.
    • You might have to re-open appointments that are completed before modifying them.

    Sample revised loop snippet integrating suggestions:

    foreach (FSSODet line in PXSelect<FSSODet,
        Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
              And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
        .Select(graph, current.SOID))
    {
        if (line.Status == "Completed")
        {
            line.Status = "Open";
            graph.Caches<FSSODet>().Update(line);
        }
    
        if (line.Qty > 0 || line.EstimatedQty > 0)
        {
            // First, update line Qty and EstimatedQty to zero
            line.Qty = 0;
            line.EstimatedQty = 0;
            graph.Caches<FSSODet>().Update(line);
    
            graph.Save.Press(); // Save early before moving on
    
            // Now update associated appointment lines EstimatedQty = 0
            foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                .Select(graph, line.SODetID))
            {
                if (apptLine.EstimatedQty > 0)
                {
                    apptLine.EstimatedQty = 0;
                    graph.Caches<FSAppointmentDet>().Update(apptLine);
                }
            }
    
            graph.Save.Press(); // Persist appt changes
        }
    }
    

    Summary checklist

    • Make sure you zero out both FSSODet.Qty and FSSODet.EstimatedQty.
    • Persist changes after updating service order lines.
    • Then zero out appointment line EstimatedQty, persist changes.
    • Validate if appointment lines or service order lines are not locked by status.
    • Check that the queries in your code are selecting all relevant appointment lines.
    • Possibly debug or log counts of appointment lines being updated to ensure coverage.
    • If the appointment lines are in "Completed" status, you may need to re-open them before updating quantities.

    If you want, I can help you modify your whole code again following these steps to avoid this validation error. Just let me know!

  5. User

    Yeah kindly regenerate it

  6. Assistant

    Certainly! Below is a revised and fully refactored version of your SOForceCompleteProcess graph's ProcessOrders method that addresses the error by:

    • Updating both Qty and EstimatedQty to zero on service order lines
    • Ensuring appointment lines' EstimatedQty is set to zero afterward
    • Persisting changes progressively at correct points to keep caches and validations consistent
    • Handling line statuses properly and carefully updating related appointment lines

    Complete updated code snippet for ProcessOrders method:

    public static void ProcessOrders(List<FSServiceOrder> list)
    {
        var graph = PXGraph.CreateInstance<ServiceOrderEntry>();
    
        foreach (var order in list)
        {
            try
            {
                graph.Clear();
                graph.ServiceOrderRecords.Current =
                    graph.ServiceOrderRecords.Search<FSServiceOrder.refNbr>(
                        order.RefNbr, order.SrvOrdType);
    
                if (graph.ServiceOrderRecords.Current?.Status == "W")
                {
                    var current = graph.ServiceOrderRecords.Current;
    
                    // Step 1: Set order status to Open, unhold & reopen if necessary
                    current.Status = "O";
                    current.Completed = false;
                    current.OpenDoc = true;
                    graph.ServiceOrderRecords.Cache.SetValueExt<FSServiceOrder.hold>(current, false);
                    graph.ServiceOrderRecords.Update(current);
    
                    graph.Actions.PressSave(); // Persist changes early
    
                    // Step 2: Iterate through Inventory Item service order lines
                    foreach (FSSODet line in PXSelect<FSSODet,
                        Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
                              And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
                        .Select(graph, current.SOID))
                    {
                        bool shouldUpdate = false;
    
                        // If line is completed, set status to Open
                        if (line.Status == "Completed")
                        {
                            line.Status = "Open";
                            shouldUpdate = true;
                        }
    
                        // If Qty or EstimatedQty > 0, zero them out
                        if (line.Qty > 0 || line.EstimatedQty > 0)
                        {
                            line.Qty = 0;
                            line.EstimatedQty = 0;
                            shouldUpdate = true;
                        }
    
                        if (shouldUpdate)
                        {
                            graph.Caches<FSSODet>().Update(line);
                            graph.Save.Press(); // Save quickly to ensure proper state before appointment update
    
                            // Now update associated appointment lines
                            foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                                Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                                .Select(graph, line.SODetID))
                            {
                                if (apptLine.EstimatedQty > 0)
                                {
                                    apptLine.EstimatedQty = 0;
                                    graph.Caches<FSAppointmentDet>().Update(apptLine);
                                }
                            }
    
                            graph.Save.Press(); // Persist appointment line changes
                        }
                    }
    
                    // Step 3: Mark order as Completed again
                    current.Status = "C";
                    current.Completed = true;
                    current.OpenDoc = false;
                    graph.ServiceOrderRecords.Update(current);
    
                    graph.Actions.PressSave();
    
                    PXProcessing<FSServiceOrder>.SetInfo($"Order {current.RefNbr} reopened, inventory deallocated, and marked as completed.");
                }
            }
            catch (Exception ex)
            {
                PXProcessing<FSServiceOrder>.SetError(ex);
            }
        }
    }
    

    Key changes summary:

    • Set both Qty and EstimatedQty of service order lines to 0 before appointment lines.
    • Save graph after updating each service order line before updating related appointment lines — helps keep the graph in a consistent state.
    • Update appointment lines' EstimatedQty to 0, then save again.
    • Open/reopen the service order before making changes; close it again at the end.
    • Used graph.Actions.PressSave() which is more semantically correct than calling graph.Save.Press() multiple times.
    • Added boolean shouldUpdate to avoid unnecessary updates/saves when no change is needed.

    Additional recommendations

    • Test this in a non-production environment.
    • Add error handling/logging as needed.
    • Check that no business logic customization elsewhere conflicts with these changes.

    If you want me to help integrate this into a full class or assist with any other part, just ask!

  7. User

    new error : Error: The record cannot be saved.

  8. Assistant

    The generic "The record cannot be saved." error often indicates that some validation or business logic is preventing the save, but the exact cause may be hidden.

    Given your scenario—setting quantities to zero and changing statuses—I suggest several targeted steps and refinements to identify and fix the issue:


    Common reasons for "The record cannot be saved." in your context:

    1. Required fields missing or invalid data after updates.

    2. Status transition conflicts or business logic preventing the save (e.g., you might be updating a line that cannot be updated when completed indirectly).

    3. Caches out of sync or partial updates that break invariants at save time.

    4. Some extensions or event handlers (RowPersisting, FieldUpdating etc.) blocking the save.


    What to try next:

    1. Wrap Save in try/catch, collect inner exceptions & debug logs

    To get more detailed information on what prevents saving, wrap your graph.Actions.PressSave() inside try/catch and output full exception details (with inner exceptions):

    try
    {
        graph.Actions.PressSave();
    }
    catch(Exception ex)
    {
        PXProcessing<FSServiceOrder>.SetError($"Error saving order {current.RefNbr}: {ex.Message} - {ex.InnerException?.Message}");
        throw;
    }
    

    This might reveal inner errors you aren’t seeing and lead to a precise fix.


    2. Verify all required fields on FSSODet lines are filled

    Before saving each line, ensure nothing essential is missing. Especially consider:

    • Qty and EstimatedQty cannot be negative (which you don't have here)
    • Inventory-related fields like InventoryID, UOM are set
    • Any custom fields mandatory in your project

    You can verify each line for missing values:

    if (line.InventoryID == null)
    {
        throw new PXException($"InventoryID missing on line {line.LineNbr}.");
    }
    

    3. Handle line status carefully

    Instead of directly setting line.Status = "Open" or "Completed", use field sets or method calls provided by the system logic where possible.

    Sometimes you might need to call base graph methods or raise FieldUpdated events to reflect changes properly:

    graph.Caches<FSSODet>().SetValueExt<FSSODet.status>(line, "Open");
    

    rather than direct assignment, to trigger proper validation.


    4. Save changes at fewer points, batch updates, and finalize at once

    Excessive multiple saves can cause locking or partial update conflicts.

    Try:

    • Update all service order lines first (Qty, EstimatedQty, Status)
    • Update all appointment lines
    • Then call Save once at the end.

    5. Verify Appointment lines are editable (not Closed/Cancelled)

    If appointment lines are completed/closed or otherwise locked, saves will fail.

    You can check appointment status before updating:

    FSAppointment appt = PXSelect<FSAppointment,
        Where<FSAppointment.appointmentID, Equal<Required<FSAppointmentDet.appointmentID>>>>
        .Select(graph, apptLine.AppointmentID);
    
    if (appt != null && appt.Status == "Completed")
    {
        PXProcessing<FSServiceOrder>.SetWarning($"Cannot update appointment line Qty on completed appointment {appt.RefNbr}");
        continue; // or handle appropriately
    }
    

    Example of a safer batch update approach

    public static void ProcessOrders(List<FSServiceOrder> list)
    {
        var graph = PXGraph.CreateInstance<ServiceOrderEntry>();
    
        foreach (var order in list)
        {
            try
            {
                graph.Clear();
                graph.ServiceOrderRecords.Current =
                    graph.ServiceOrderRecords.Search<FSServiceOrder.refNbr>(order.RefNbr, order.SrvOrdType);
    
                if (graph.ServiceOrderRecords.Current?.Status == "W")
                {
                    var current = graph.ServiceOrderRecords.Current;
    
                    // Open the order first
                    current.Status = "O";
                    current.Completed = false;
                    current.OpenDoc = true;
                    graph.ServiceOrderRecords.Cache.SetValueExt<FSServiceOrder.hold>(current, false);
                    graph.ServiceOrderRecords.Update(current);
    
                    // Update all inventory item lines qty and estimatedqty to zero, open status
                    foreach (FSSODet line in PXSelect<FSSODet,
                        Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
                              And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
                        .Select(graph, current.SOID))
                    {
                        graph.Caches<FSSODet>().SetValueExt<FSSODet.status>(line, "Open");
                        graph.Caches<FSSODet>().SetValueExt<FSSODet.qty>(line, 0m);
                        graph.Caches<FSSODet>().SetValueExt<FSSODet.estimatedQty>(line, 0m);
                        graph.Caches<FSSODet>().Update(line);
                    }
    
                    graph.Actions.PressSave();
    
                    // Now update all related appointment lines estimatedQty = 0
                    foreach (FSSODet line in PXSelect<FSSODet,
                        Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
                              And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
                        .Select(graph, current.SOID))
                    {
                        foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                            Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                            .Select(graph, line.SODetID))
                        {
                            if (apptLine.EstimatedQty > 0)
                            {
                                // Optional: check appointment status to skip locked lines
                                FSAppointment appt = PXSelect<FSAppointment,
                                    Where<FSAppointment.appointmentID, Equal<Required<FSAppointmentDet.appointmentID>>>>
                                    .Select(graph, apptLine.AppointmentID);
                                if (appt != null && appt.Status == "Completed")
                                {
                                    PXProcessing<FSServiceOrder>.SetWarning($"Skipped appointment line in completed appointment {appt.RefNbr}");
                                    continue;
                                }
    
                                graph.Caches<FSAppointmentDet>().SetValueExt<FSAppointmentDet.estimatedQty>(apptLine, 0m);
                                graph.Caches<FSAppointmentDet>().Update(apptLine);
                            }
                        }
                    }
    
                    graph.Actions.PressSave();
    
                    // Finally mark order completed again
                    current.Status = "C";
                    current.Completed = true;
                    current.OpenDoc = false;
                    graph.ServiceOrderRecords.Update(current);
    
                    graph.Actions.PressSave();
    
                    PXProcessing<FSServiceOrder>.SetInfo($"Order {current.RefNbr} updated successfully.");
                }
            }
            catch (Exception ex)
            {
                PXProcessing<FSServiceOrder>.SetError(ex);
            }
        }
    }
    

    Summary

    • Use SetValueExt for status/field updates (triggers all validations and events).
    • Avoid frequent saves; batch updates before saving.
    • Add appointment status checks before updating lines.
    • Wrap saves in try/catch and log detailed errors to diagnose.
    • Verify no mandatory fields are missing.

    If this still doesn't resolve the error or you get a more detailed error message from the inner exception, please share that text and I can assist further!

  9. User

    i got the same error , canot save

  10. Assistant

    The generic "The record cannot be saved" error in Acumatica usually hints at a validation issue or event handler blocking the save, but the cause may not always be transparent.

    Given your scenario—resetting service order and appointment line quantities and statuses—here’s a deeper troubleshooting and refined approach, including how to pinpoint the exact reason.


    Step 1: Get the exact error causing "The record cannot be saved"

    Use Acumatica’s exception detail to get more info:

    Replace your save calls with a helper method that unwraps exceptions and logs details:

    private static void TrySave(PXGraph graph, string context)
    {
        try
        {
            graph.Actions.PressSave();
        }
        catch (PXOuterException outerEx)
        {
            var sb = new System.Text.StringBuilder();
            sb.AppendLine($"Error saving in context '{context}':");
    
            foreach (var ex in outerEx.InnerExceptions)
            {
                sb.AppendLine(ex.Message);
            }
            throw new PXException(sb.ToString());
        }
        catch (Exception ex)
        {
            throw new PXException($"Error saving in context '{context}': {ex.Message}", ex);
        }
    }
    

    Then replace every graph.Actions.PressSave() with TrySave(graph, "some description").


    Step 2: In case validation blocks updates on completed appointments or service orders

    You may not be allowed to update fields on completed appointments or service order lines directly.

    Solution: Temporarily reopen related appointments before update and then close again.

    Example:

    FSAppointment appt = PXSelect<FSAppointment,
        Where<FSAppointment.appointmentID, Equal<Required<FSAppointmentDet.appointmentID>>>>
        .Select(graph, apptLine.AppointmentID);
    
    if (appt != null && appt.Status == FSAppointment.status.Completed)
    {
        graph.AppointmentRecords.Current = appt;
        graph.AppointmentRecords.Current.Status = FSAppointment.status.Open;
        graph.AppointmentRecords.Update(graph.AppointmentRecords.Current);
        TrySave(graph, $"Reopen Appointment {appt.RefNbr} before update");
    
        // update appointment det lines here
    
        graph.AppointmentRecords.Current.Status = FSAppointment.status.Completed;
        graph.AppointmentRecords.Update(graph.AppointmentRecords.Current);
        TrySave(graph, $"Close Appointment {appt.RefNbr} after update");
    }
    else
    {
        // appointment is open or not completed, update lines directly
    }
    

    Similar for service order lines if needed but proceed carefully.


    Step 3: Use official Entry Graph and Cache methods

    Update records using graphs designed for those entities:

    • For updating FSServiceOrder lines, use the ServiceOrderEntry graph (graph you already have).
    • For updating appointment lines, create an instance of AppointmentEntry graph and update lines there to respect system logic.

    Example:

    // Inside your method for each service order line
    
    foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
        Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
        .Select(graph, line.SODetID))
    {
        var apptGraph = PXGraph.CreateInstance<AppointmentEntry>();
        apptGraph.AppointmentDetRecords.Current = apptGraph.AppointmentDetRecords.Search<FSAppointmentDet.appointmentDetID>(apptLine.AppointmentDetID);
    
        // Reopen appointment if needed, as above
    
        apptGraph.AppointmentDetRecords.Current.EstimatedQty = 0m;
        apptGraph.AppointmentDetRecords.Update(apptGraph.AppointmentDetRecords.Current);
    
        TrySave(apptGraph, "Appointment line Update");
    }
    

    This respects underlying event handlers and business logic.


    Step 4: Example full revised approach sketch

    public static void ProcessOrders(List<FSServiceOrder> list)
    {
        foreach (var order in list)
        {
            var soEntry = PXGraph.CreateInstance<ServiceOrderEntry>();
            soEntry.ServiceOrderRecords.Current = soEntry.ServiceOrderRecords.Search<FSServiceOrder.refNbr>(order.RefNbr, order.SrvOrdType);
    
            if (soEntry.ServiceOrderRecords.Current?.Status == "W")
            {
                var currentSO = soEntry.ServiceOrderRecords.Current;
                // Reopen service order for edits
                currentSO.Status = "O";
                currentSO.Completed = false;
                currentSO.OpenDoc = true;
                soEntry.ServiceOrderRecords.Cache.SetValueExt<FSServiceOrder.hold>(currentSO, false);
                soEntry.ServiceOrderRecords.Update(currentSO);
                TrySave(soEntry, $"Reopen Service Order {currentSO.RefNbr}");
    
                // Update SO lines
                foreach (FSSODet soLine in PXSelect<FSSODet,
                    Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
                          And<FSSODet.lineType, Equal<FSLineType.inventory_Item>>>>
                    .Select(soEntry, currentSO.SOID))
                {
                    if (soLine.Status == "Completed")
                        soEntry.Caches<FSSODet>().SetValueExt<FSSODet.status>(soLine, "Open");
    
                    soEntry.Caches<FSSODet>().SetValueExt<FSSODet.qty>(soLine, 0m);
                    soEntry.Caches<FSSODet>().SetValueExt<FSSODet.estimatedQty>(soLine, 0m);
                    soEntry.Caches<FSSODet>().Update(soLine);
                    TrySave(soEntry, $"Update SO Line {soLine.LineNbr}");
    
                    // Update appointment lines using AppointmentEntry graph
                    foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                        Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                        .Select(soEntry, soLine.SODetID))
                    {
                        var apptEntry = PXGraph.CreateInstance<AppointmentEntry>();
                        apptEntry.AppointmentDetRecords.Current = apptEntry.AppointmentDetRecords.Search<FSAppointmentDet.appointmentDetID>(apptLine.AppointmentDetID);
    
                        // Reopen appointment if needed
                        FSAppointment appt = PXSelect<FSAppointment,
                            Where<FSAppointment.appointmentID, Equal<Required<FSAppointmentDet.appointmentID>>>>
                            .Select(apptEntry, apptLine.AppointmentID);
    
                        if (appt != null && appt.Status == FSAppointment.status.Completed)
                        {
                            apptEntry.AppointmentRecords.Current = appt;
                            apptEntry.AppointmentRecords.Current.Status = FSAppointment.status.Open;
                            apptEntry.AppointmentRecords.Update(apptEntry.AppointmentRecords.Current);
                            TrySave(apptEntry, $"Reopen Appointment {appt.RefNbr}");
                        }
    
                        apptEntry.Caches<FSAppointmentDet>().SetValueExt<FSAppointmentDet.estimatedQty>(apptEntry.AppointmentDetRecords.Current, 0m);
                        apptEntry.AppointmentDetRecords.Update(apptEntry.AppointmentDetRecords.Current);
                        TrySave(apptEntry, $"Update Appointment Line {apptLine.LineNbr}");
    
                        // Close appointment again if reopened earlier
                        if (appt != null && appt.Status == FSAppointment.status.Completed)
                        {
                            apptEntry.AppointmentRecords.Current.Status = FSAppointment.status.Completed;
                            apptEntry.AppointmentRecords.Update(apptEntry.AppointmentRecords.Current);
                            TrySave(apptEntry, $"Close Appointment {appt.RefNbr}");
                        }
                    }
                }
    
                currentSO.Status = "C";
                currentSO.Completed = true;
                currentSO.OpenDoc = false;
                soEntry.ServiceOrderRecords.Update(currentSO);
                TrySave(soEntry, $"Complete Service Order {currentSO.RefNbr}");
    
                PXProcessing<FSServiceOrder>.SetInfo($"Successfully processed service order {currentSO.RefNbr}");
            }
        }
    }
    

    Final Notes:

    • This approach uses official Entry Graphs (ServiceOrderEntry, AppointmentEntry) for all updates.
    • It reopens appointments before changing lines to avoid save restrictions.
    • SetValueExt is used on all field changes to trigger validation.
    • Every save is wrapped in TrySave() to give clear error messages to debug with.
    • Remember to test thoroughly on a development environment.
    • If after this you still get errors, capture the full exception message/text and share it for further diagnosis.

    If you want, I can help you write the full class or assist with any further refinements. Just say!

  11. User

    still getting the same error ; Take a look at this FSSODet table structure and help me come up with a viable solution : SELECT TOP (1000) [CompanyID] ,[SrvOrdType] ,[RefNbr] ,[SODetID] ,[AcctID] ,[ApptCntr] ,[ApptDuration] ,[ApptEstimatedDuration] ,[ApptQty] ,[ApptTranAmt] ,[BaseBillableQty] ,[BaseEstimatedQty] ,[BaseOpenQty] ,[BaseShippedQty] ,[BillableExtPrice] ,[BillableQty] ,[BillableTranAmt] ,[BillCustomerID] ,[BillingRule] ,[BranchID] ,[Comment] ,[ContractRelated] ,[Completed] ,[ComponentID] ,[CostCodeID] ,[CoveredQty] ,[CuryApptTranAmt] ,[CuryBillableExtPrice] ,[CuryBillableTranAmt] ,[CuryDiscAmt] ,[CuryEstimatedTranAmt] ,[CuryExtCost] ,[CuryExtraUsageUnitPrice] ,[CuryInfoID] ,[CuryUnitCost] ,[CuryUnitPrice] ,[DiscountID] ,[DiscAmt] ,[DiscPct] ,[DiscountSequenceID] ,[DocumentDiscountRate] ,[EquipmentAction] ,[EquipmentItemClass] ,[EquipmentLineRef] ,[EstimatedDuration] ,[EstimatedQty] ,[EstimatedTranAmt] ,[ExpireDate] ,[ExtCost] ,[ExtraUsageQty] ,[ExtraUsageUnitPrice] ,[GroupDiscountRate] ,[InventoryID] ,[InvtMult] ,[IsBillable] ,[IsFree] ,[IsPrepaid] ,[LineNbr] ,[LineRef] ,[LineType] ,[LinkedDocRefNbr] ,[LinkedDocType] ,[LinkedEntityType] ,[LinkedLineNbr] ,[LotSerialNbr] ,[ManualDisc] ,[AutomaticDiscountsDisabled] ,[ManualPrice] ,[ManualCost] ,[NewTargetEquipmentLineNbr] ,[OpenQty] ,[Operation] ,[EnablePO] ,[CuryOrigUnitCost] ,[OrigUnitCost] ,[POSource] ,[POVendorID] ,[POVendorLocationID] ,[POSiteID] ,[POType] ,[PONbr] ,[POLineNbr] ,[POStatus] ,[POCompleted] ,[PostID] ,[ProjectID] ,[ProjectTaskID] ,[Scheduled] ,[ScheduleDetID] ,[ScheduleID] ,[ShipComplete] ,[ShipDate] ,[ShippedQty] ,[SiteID] ,[SiteLocationID] ,[SMEquipmentID] ,[SOID] ,[SourceLineID] ,[SourceLineNbr] ,[SourceNoteID] ,[StaffID] ,[Status] ,[SortOrder] ,[SubID] ,[SubItemID] ,[TaxCategoryID] ,[TranDate] ,[TranDesc] ,[UnassignedQty] ,[UnitCost] ,[UnitPrice] ,[UOM] ,[Warranty] ,[CreatedByID] ,[CreatedByScreenID] ,[CreatedDateTime] ,[LastModifiedByID] ,[LastModifiedByScreenID] ,[LastModifiedDateTime] ,[NoteID] ,[tstamp] FROM [MyStoreInstance].[dbo].[FSSODet]

  12. Assistant

    Thank you for sharing the detailed FSSODet table structure. This provides valuable insight into the fields involved, particularly those related to quantities and statuses, which are typically the source of errors like:

    "The specified estimated quantity 0.0000 is less than the sum of the estimated quantities of all lines 1.0000 in the associated appointment(s)."


    Understanding The Key Fields Relevant to Your Issue

    From the structure, consider the following important fields and their role:

    FieldExplanation
    EstimatedQtyThe estimated quantity for the service order line — must equal or exceed sum of appointment lines.
    ApptQty (Appointment Quantity)Quantity assigned to associated appointments (likely a summary).
    OpenQty, BaseOpenQtyQuantity still open/unprocessed.
    ShippedQty, BaseShippedQtyActual shipped quantities if applicable.
    CompletedBoolean indicating if the line is completed.
    StatusLine status, e.g., Open, Completed, etc.
    SOIDService Order ID (PK to parent order).
    SODetIDPrimary Key of this service order detail line.
    LineTypeType of line, e.g., Inventory_Item, Service, etc.
    UOMUnit of measure; consistency important when updating qty fields.

    Why Your Error Occurs

    The validation error means:

    • Your Service Order line EstimatedQty is set to 0
    • But one or more Appointment lines linked via SODetID still have EstimatedQty > 0
    • The system enforces this constraint to prevent mismatched quantities between SO and Appointments

    What Must Your Code Do to Avoid This?

    To properly deallocate inventory and avoid this error, the process must:

    1. Set Appointment lines’ EstimatedQty to zero first

    2. Then set Service Order lines' EstimatedQty and possibly other quantity fields (Qty, OpenQty, etc.) to zero

    3. Save these changes in the correct order, ensuring all related caches and business logic validations pass

    4. Maintain consistency between other quantity fields (like ApptQty or OpenQty), because some logic might be validating them


    Viable Solution Steps Based on Your Table Structure

    1. Clear Appointment Lines Quantities First

    Update all FSAppointmentDet records that reference the FSSODet.SODetID lines setting:

    • EstimatedQty = 0
    • And if present/used, fields like ApptQty or similar quantities may also need clearing, depending on your business logic

    Why first? Because appointment lines have the dependent quantities that should be reduced before their source lines on the SO are adjusted.

    2. Clear Relevant FSSODet Quantities Next

    Once Appointment lines are cleared, update the SO lines to zero for:

    • EstimatedQty
    • ApptQty (if relevant)
    • Qty
    • OpenQty and BaseOpenQty
    • Possibly Completed = false if necessary to allow changes

    Make sure to also handle Status correctly, e.g., reopen lines if marked completed before quantity reset.

    3. Save Changes with Proper Graphs & Methods

    • Use AppointmentEntry graph to modify appointment lines.
    • Use ServiceOrderEntry graph for service order lines.

    Use SetValueExt to update fields to ensure all business logic and event handlers are triggered.


    Example Adjusted Code Using Your Table Context (Simplified)

    public static void ProcessOrders(List<FSServiceOrder> list)
    {
        foreach (var order in list)
        {
            var soGraph = PXGraph.CreateInstance<ServiceOrderEntry>();
            soGraph.ServiceOrderRecords.Current = soGraph.ServiceOrderRecords.Search<FSServiceOrder.refNbr>(order.RefNbr, order.SrvOrdType);
    
            if (soGraph.ServiceOrderRecords.Current?.Status == "W")
            {
                var currentSO = soGraph.ServiceOrderRecords.Current;
    
                // Step 1: Set SO status to Open (uncomplete)
                currentSO.Status = "O";
                currentSO.Completed = false;
                currentSO.OpenDoc = true;
                soGraph.ServiceOrderRecords.Cache.SetValueExt<FSServiceOrder.hold>(currentSO, false);
                soGraph.ServiceOrderRecords.Update(currentSO);
                soGraph.Actions.PressSave();
    
                // Step 2: For each relevant SO line (Inventory_Item)
                foreach (FSSODet soLine in PXSelect<FSSODet,
                    Where<FSSODet.sOID, Equal<Required<FSServiceOrder.sOID>>,
                          And<FSSODet.lineType, Equal<FSLineType.Inventory_Item>>>>
                    .Select(soGraph, currentSO.SOID))
                {
                    // Step 2a: Clear Appointment lines first
                    var apptGraph = PXGraph.CreateInstance<AppointmentEntry>();
    
                    foreach (FSAppointmentDet apptLine in PXSelect<FSAppointmentDet,
                        Where<FSAppointmentDet.sODetID, Equal<Required<FSSODet.sODetID>>>>
                        .Select(soGraph, soLine.SODetID))
                    {
                        apptGraph.AppointmentDetRecords.Current = apptGraph.AppointmentDetRecords.Search<FSAppointmentDet.appointmentDetID>(apptLine.AppointmentDetID);
    
                        apptGraph.Caches<FSAppointmentDet>().SetValueExt<FSAppointmentDet.estimatedQty>(apptGraph.AppointmentDetRecords.Current, 0m);
                        apptGraph.Caches<FSAppointmentDet>().Update(apptGraph.AppointmentDetRecords.Current);
    
                        apptGraph.Actions.PressSave();
                    }
    
                    // Step 2b: Now clear SO line quantities
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.estimatedQty>(soLine, 0m);
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.apptQty>(soLine, 0m);
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.qty>(soLine, 0m);
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.openQty>(soLine, 0m);
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.baseOpenQty>(soLine, 0m);
    
                    // Optionally set completed false and status open
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.completed>(soLine, false);
                    soGraph.Caches<FSSODet>().SetValueExt<FSSODet.status>(soLine, "Open");
    
                    soGraph.Caches<FSSODet>().Update(soLine);
                    soGraph.Actions.PressSave();
                }
    
                // Step 3: Mark SO completed again if needed
                currentSO.Status = "C";
                currentSO.Completed = true;
                currentSO.OpenDoc = false;
                soGraph.ServiceOrderRecords.Update(currentSO);
                soGraph.Actions.PressSave();
    
                PXProcessing<FSServiceOrder>.SetInfo($"Service Order {currentSO.RefNbr} updated successfully.");
            }
        }
    }
    

    Important Notes / Tips

    • SetValueExt is crucial: setting fields directly without SetValueExt often bypasses required events and validation logic.
    • Save after appointment lines update: you must save appointment changes first before doing SO line changes.
    • Clear all related quantity fields on SO line to ensure validation does not fail.
    • Updating status & completed flags carefully to allow edits.
    • If you have customized or overridden event handlers on these DACs, ensure they allow the quantity to be set to zero or temporarily disabled as needed.

    Conclusion

    Your error is caused by quantity mismatch between appointment lines and SO lines. The solution is to:

    1. Clear all quantities on appointment lines first (including EstimatedQty).
    2. Then clear all related quantity fields on service order lines.
    3. Make sure to save changes after each step.
    4. Use SetValueExt (never assign fields directly).
    5. Handle statuses and completed flags to not block changes.

    If you want, I can prepare a full, ready-to-use graph customization class that implements this, including error handling and logging.

    Let me know if you'd like me to do that!