Skip to main content
Solved

APTran costcode Line control


Forum|alt.badge.img

Good day,

I have a customization project that a part of it consists of establishing a control of line creation on the Purchase order and the Bills and adjustments based on the costcode, if the costcode entered by the user does not belong to the combination of the project, project task and account group the line should not be saved, and an exception should be thrown, but my issue is that in the PO it is working, but in the Bills and adjustment is giving me an error: Error: Another process has added the 'APInvoice' record. Please try again. I don't know if there is a validation or something I need to change, I will appreciate suggestions.

 

Thank you.

[PXOverride]
        public void Persist(Action del)
        {
            APInvoice apvar = Base.Document.Current;
            var BillsCache = Base.Caches[typeof(APTran)];

                foreach (APTran apTran in PXSelect<APTran, Where<APTran.refNbr, Equal<Required<APTran.refNbr>>,
                        And<APTran.tranType, Equal<Required<APTran.tranType>>>>>.Select(this.Base, apvar.RefNbr, apvar.DocType))
                {

                    // Get the Project, ProjectTask, and Account from the APTran line
                    int? projectID = apTran.ProjectID;
                    int? taskID = apTran.TaskID;
                    int? accountID = apTran.AccountID;
                    int? costcode = apTran.CostCodeID;

                    PMCostBudget costBudget = SelectFrom<PMCostBudget>
                    .InnerJoin<Account>.On<PMCostBudget.accountGroupID.IsEqual<Account.accountGroupID>>
                    .Where<PMCostBudget.projectID.IsEqual<@P.AsInt>
                    .And<PMCostBudget.costCodeID.IsEqual<@P.AsInt>
                    .And<PMCostBudget.projectTaskID.IsEqual<@P.AsInt>
                    .And<Account.accountID.IsEqual<@P.AsInt>>>>>
                    .View.SelectSingleBound(this.Base, null, projectID, costcode, taskID, accountID);
                    if (costBudget == null)
                    {
                        throw new PXException("The specified costcode is not present in the project budget with the combination of the project task and the account group.");

                    }

                }
            del?.Invoke();
        }

 

Best answer by orlandonegron43

Django wrote:

Do you have any other published customizations that would impact this area? Sounds like there is something else that is touching the APInvoice record.

I wonder if calling the new PXGraph.PrePersist() would be a better option for you since you’re only wanting to do a validation check.As you’d expect, it is called before Persist is called and allows you to keep your code out of the Persist routines.

I found the issue, the problem was the Numbering sequence, I used a snapshot in my localhost, and it had thousands of Bills and adjustments records, and I forgot that I went to Numbering sequence and turned off the manual numbering, the problem was that the sequence started again from 000001 and kept increasing and there was already Bills that had the same sequence, and when for example I tried to save the Bill 000049 it gave the error because it already existed by manually entering the reference number.

 

Thanks for the response.

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

3 replies

Forum|alt.badge.img+5
  • Captain II
  • 499 replies
  • May 29, 2024

Do you have any other published customizations that would impact this area? Sounds like there is something else that is touching the APInvoice record.

I wonder if calling the new PXGraph.PrePersist() would be a better option for you since you’re only wanting to do a validation check.As you’d expect, it is called before Persist is called and allows you to keep your code out of the Persist routines.


Forum|alt.badge.img
Django wrote:

Do you have any other published customizations that would impact this area? Sounds like there is something else that is touching the APInvoice record.

I wonder if calling the new PXGraph.PrePersist() would be a better option for you since you’re only wanting to do a validation check.As you’d expect, it is called before Persist is called and allows you to keep your code out of the Persist routines.

I found the issue, the problem was the Numbering sequence, I used a snapshot in my localhost, and it had thousands of Bills and adjustments records, and I forgot that I went to Numbering sequence and turned off the manual numbering, the problem was that the sequence started again from 000001 and kept increasing and there was already Bills that had the same sequence, and when for example I tried to save the Bill 000049 it gave the error because it already existed by manually entering the reference number.

 

Thanks for the response.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2640 replies
  • June 3, 2024

Thank you for sharing your solution with the community @orlandonegron43!


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