Skip to main content
Solved

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

  • February 18, 2022
  • 1 reply
  • 185 views

darylbowman
Captain II
Forum|alt.badge.img+13

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.

Best answer by darylbowman

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

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

1 reply

darylbowman
Captain II
Forum|alt.badge.img+13
  • Author
  • 1749 replies
  • Answer
  • February 28, 2022

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


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