Hey Guys,
Â
Summary:
We are experiencing an issue with saving changes made to the Project Attributes (attributes section of the PM304500 screen) when they have been modified. The goal is to save the changes automatically when a project attribute is updated. However, attempts to implement this using the PXLongOperation
class have not been successful, and we encounter the error "The record could not be saved".
Detailed Description:
We have implemented a customization for the PMQuoteMaint
graph to save changes to project attributes automatically when they are modified. This involves setting a flag when an attribute value changes and then attempting to save the changes using a custom action with PXLongOperation
.
Despite various attempts, the save operation fails, and we receive the error "The record could not be saved". Below is the code we have used:
Â
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Common;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.PM;
namespace PX.Objects.PM
{
  // Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
  public class PMQuoteMaint_Extension : PXGraphExtension<PX.Objects.PM.PMQuoteMaint>
  {
    #region Event Handlers
    // Define a flag to indicate that a save is required
    private bool saveRequired;
    protected virtual void CSAnswers_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
    {
      // Call the base implementation of the RowUpdated event
      InvokeBaseHandler?.Invoke(cache, e);
      var row = (CSAnswers)e.Row;
      var oldRow = (CSAnswers)e.OldRow;
      if (row == null || oldRow == null) return;
      // Check if the value has changed
      if (!Equals(row.Value, oldRow.Value))
      {
        // Get the PMQuote record
        var quote = Base.Quote.Current;
        if (quote != null && quote.Status == "C")
        {
          // Enable the Save action and set the saveRequired flag
          // Acuminator disable once PX1070 UiPresentationLogicInEventHandlers tJustification]
          Base.ActionsÂ"Save"].SetEnabled(true);
          saveRequired = true;
        }
      }
    }
    protected virtual void PMQuote_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
    {
      // Call the base implementation of the RowSelected event
      InvokeBaseHandler?.Invoke(cache, e);
      // Perform the save operation if required
      if (saveRequired)
      {
        saveRequired = false;
        // Acuminator disable once PX1043 SavingChangesInEventHandlers fJustification]
        Base.Actions.PressSave();
      }
    }
    #endregion
    #region Actions
    public PXAction<PMQuote> PerformSaveAction;
    iPXButton(CommitChanges = true)]
    iPXUIField(DisplayName = "Perform Save Action", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
    protected virtual IEnumerable performSaveAction(PXAdapter adapter)
    {
      if (Base.Quote.Current != null)
      {
        var quoteNbr = Base.Quote.Current.QuoteNbr;
        PXLongOperation.StartOperation(Base, delegate ()
        {
          SaveQuote(quoteNbr);
        });
      }
      return adapter.Get();
    }
    private static void SaveQuote(string quoteNbr)
    {
      if (quoteNbr == null) return;
      var graph = PXGraph.CreateInstance<PMQuoteMaint>();
      var quote = graph.Quote.Search<PMQuote.quoteNbr>(quoteNbr);
      if (quote != null)
      {
        graph.Quote.Current = quote;
        graph.Actions.PressSave();
      }
    }
    #endregion
  }
}
Â
Error Message:
When attempting to save the changes, we encounter the following error:
-----------------------------------------------------
Error: The record could not be saved.
-----------------------------------------------------
Â
Screenshot:
![](https://uploads-us-west-2.insided.com/acumatica-en/attachment/0866d8e4-1706-4558-9f7a-e8795181b71a.png)
Steps to Reproduce:
- Navigate to the Project Quotes screen (PM304500).
- Modify any project attribute in the attributes section.
- Attempt to save the changes.
Expected Behavior:
The changes to the project attributes should be saved automatically when they are modified.
Actual Behavior:
An error is encountered, and the changes are not saved. The error message states that "The record could not be saved".
Additional Information:
We have tried incorporating the PXLongOperation
in both the RowUpdated
event handler and a custom action, but the issue persists. It seems that the PXLongOperation
cannot be started within an event handler, and even when using a custom action, the error still occurs.
We would appreciate any assistance or guidance on how to properly implement this functionality to save changes to the project attributes automatically when they are modified.
Thank you.