Hi,
I'm developing a custom setup screen in Acumatica 2025 R2 (Modern UI) that maintains configuration settings at the organization level.
The requirement is to maintain one setup record per OrganizationID. Multiple branches belonging to the same organization should access and update the same configuration record.
I'm experiencing an issue where the existing record is successfully retrieved from the database and displayed on the screen. However, when I modify a field and attempt to save it for the first time, Acumatica throws:
Error: Another process has added the 'CustomOrgSetup' record. Your changes will be lost.
Interestingly, when I retry the operation, the record saves successfully.
I'm trying to understand whether my custom view delegate is interfering with Acumatica's normal cache and persistence handling.
1. DAC Definition
OrganizationID is the primary key.
[Serializable]
[PXCacheName("Custom Organization Setup")]
public class CustomOrgSetup : PXBqlTable, IBqlTable
{
#region OrganizationID
[PXDBInt(IsKey = true)]
[PXDefault]
[PXUIField(DisplayName = "Organization", Visible = false)]
public virtual int? OrganizationID { get; set; }
public abstract class organizationID
: PX.Data.BQL.BqlInt.Field<organizationID>
{
}
#endregion
}2. Graph – Primary View
The setup record is filtered based on the organization associated with the currently selected branch.
public PXSave<CustomOrgSetup> Save;
public PXCancel<CustomOrgSetup> Cancel;
public SelectFrom<CustomOrgSetup>
.InnerJoin<PX.Objects.GL.Branch>
.On<PX.Objects.GL.Branch.organizationID
.IsEqual<CustomOrgSetup.organizationID>>
.Where<PX.Objects.GL.Branch.branchID
.IsEqual<AccessInfo.branchID.FromCurrent>>
.View Setup;
public PXFilter<CustomOrgSetupDialog> SetupDialog;
public PXFilter<CustomOrgSetupDialog> UserSyncDialog;3. Custom View Delegate
I'm using the following delegate to load the current organization's setup record.
protected virtual IEnumerable setup()
{
int? organizationID =
PXAccess.GetParentOrganizationID(
Accessinfo.BranchID);
if (organizationID == null)
{
throw new PXException(
"Organization not found.");
}
// First check the graph cache.
// Preserve unsaved changes.
CustomOrgSetup cachedRow =
Setup.Cache.Cached
.Cast<CustomOrgSetup>()
.FirstOrDefault(
x => x.OrganizationID == organizationID);
if (cachedRow != null)
{
PXEntryStatus status =
Setup.Cache.GetStatus(cachedRow);
if (status == PXEntryStatus.Updated)
{
yield return cachedRow;
yield break;
}
}
CustomOrgSetup row = GetSetup(this);
if (row != null)
yield return row;
}The helper method retrieves the existing database record:
private static CustomOrgSetup GetSetup(PXGraph graph)
{
int? organizationID =
PXAccess.GetParentOrganizationID(
graph.Accessinfo.BranchID);
if (organizationID == null)
{
throw new PXException(
"Organization not found.");
}
return SelectFrom<CustomOrgSetup>
.Where<
CustomOrgSetup.organizationID
.IsEqual<@P.AsInt>>
.View.ReadOnly
.Select(graph, organizationID);
}4. Observed Behaviour
-
On initial screen load, the
GetSetup()method successfully retrieves the existing database record, including previously saved field values. -
When I modify a field and attempt to save, Acumatica throws the duplicate-record error.
-
Retrying the operation sometimes allows the record to be saved successfully.
-
If I remove the custom
setup()delegate, the existing record does not load as expected. -
If I use
.View.ReadOnlyon the primary view, the record is displayed, but the fields are not editable. -
Using a normal
.View.Select()instead of.View.ReadOnly.Select()in the delegate did not consistently retrieve the existing database values.
I also inspected the record during RowPersisting and received:
OrganizationID: 5
Operation: Normal, Update
Status: UpdatedThis suggests the record is marked as Updated during persistence, despite the duplicate-record error.
5. Questions
-
Is using
.View.ReadOnly.Select()inside a custom delegate for an editable primary view causing the first-save issue? -
What is the recommended approach for loading an existing organization-specific setup record while preserving unsaved changes?
-
Is there a way to define an editable primary view filtered by the current branch's
OrganizationIDwithout using a custom delegate? -
Why might Acumatica throw the duplicate-insert error on the first attempt but successfully save on the second attempt, even though
RowPersistingreports an Update operation? -
Is there a recommended native Acumatica setup-screen pattern for handling both new and existing organization-level records through standard
PXSavefunctionality?
I've also reviewed native setup screens such as GLSetupMaint (GL102000), but those appear to follow a simpler setup structure without organization-based filtering.
Ideally, I would like to use Acumatica's standard record loading, caching, and persistence behavior without manually managing cache statuses or overriding the Save process.
Any suggestions or examples would be greatly appreciated.
Thank you!