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();
}