Solved

'Another process has added the 'ContractBillingSchedule' record. Your changes will be lost.'

  • 18 February 2022
  • 1 reply
  • 150 views

Badge +11

I am attempting to create a Project for a Business Account programmatically.

 

	public class ExtendProjects_BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
{
public PXAction<BAccount> CreateServicesProjectAction;
[PXMassAction]
[PXButton(CommitChanges = true, Category = "Record Creation")]
[PXUIField(DisplayName = "Create 'Services' Project")]
protected virtual void createServicesProjectAction()
{
BAccount bAccount = Base.BAccount.Current;
if (bAccount is null) return;

PXLongOperation.StartOperation(Base, delegate ()
{
CreateServicesProject(bAccount.BAccountID);
});
}

public static void CreateServicesProject(int? bAccountID)
{
if (bAccountID is null) return;

var bAccountGraph = PXGraph.CreateInstance<BusinessAccountMaint>();
BAccount bAccount = bAccountGraph.BAccount.Current = bAccountGraph.BAccount.Search<BAccount.bAccountID>(bAccountID);
if (bAccount is null) return;

var templateGraph = PXGraph.CreateInstance<PX.Objects.PM.TemplateMaint>();
PMProject template = templateGraph.Project.Search<PMProject.contractCD>("SERVICES");
if (template is null)
throw new PXException("A 'Services' template does not exist.");

PMProject servicesProj = SelectFrom<PMProject>.Where<PMProject.customerID.IsEqual<@P.AsInt>.And<PMProject.templateID.IsEqual<@P.AsInt>>>.View.ReadOnly.SelectWindowed(new PXGraph(), 0, 1, bAccount.BAccountID, template.ContractID);
if (servicesProj is null)
{
var projectGraph = PXGraph.CreateInstance<ProjectEntry>();
PMProject project = projectGraph.Project.Current = projectGraph.Project.Insert(new PMProject());
projectGraph.Project.SetValueExt<PMProject.customerID>(project, bAccount.BAccountID);
projectGraph.Project.SetValueExt<PMProject.templateID>(project, template.ContractID);
projectGraph.Project.SetValueExt<PMProject.description>(project, "Services");
projectGraph.Project.Update(project);

projectGraph.Save.Press();
}
}
}

Sometimes it succeeds, but for some accounts, it fails repeatedly with 'Another process has added the 'ContractBillingSchedule' record. Your changes will be lost.'

 

Is this code-related or a bug? I did see a few other posts of similar errors in some versions of 21 R1, but we’re in 21 R2.

icon

Best answer by darylbowman 28 February 2022, 17:01

View original

1 reply

Badge +11

It appears to be a bug. The code works fine in 21.209.0034

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved