Hello there,
I have a screen that user enters some cashflow projections for our projects. This screen keeps the different versions of cashflw projections. At any given time each project can have only one “Current Revision”. When a new projection entered r an existing projection is changed as “IsCurrent = true”, I would like to update a field (UsrLGRevisionID) in PMProject extension with the current projection “RevisionID”. The only problem that I have when I insert/update a new projection as Current, it doesn’t update the PMProject but if second time I just set the checkbox of IsCurrent” off and then on, it updates the PMProject Extension. Here is my even handler. Any help is appreciated.
protected void PMCashflowProjection_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
PMCashflowProjection row = e.Row as PMCashflowProjection;
// Only one Current Revision should exist for each project.
// When a Cashflow Projection is set to "Current", the rest of the projections shouldn't be current.
bool isCurrent = false;
var revisionsFilter = this.RevisionsFilter.Select();
if (row.IsCurrent == true)
{
foreach (PMCashflowProjection revisions in revisionsFilter)
{
if (revisions.RevisionID != row.RevisionID)
{
if (revisions.IsCurrent == true)
{
Caches[typeof(PMCashflowProjection)].SetValue<PMCashflowProjection.isCurrent>(revisions, false);
Caches[typeof(PMCashflowProjection)].Persist(revisions, PXDBOperation.Update);
}
}
else
{
isCurrent = true;
}
}
}
else
{
foreach (PMCashflowProjection revisions in revisionsFilter)
{
if (revisions.IsCurrent == true)
{
isCurrent = true;
continue;
}
}
}
// ONE Current Projection should exist for each project.
if (isCurrent != true)
{
throw new PXException(PMMessages_Extension.NoneOfTheCashflowRevisionsIsFlaggedAsCurrent);
}
// Project master record should be updated with the Current Cashflow Projection reference.
var projectsFilter = this.ProjectsFilter.Select();
foreach (PMProject projects in projectsFilter)
{
if (projects.ContractID == row.ProjectID)
{
//PMProject_Extension project = projects.GetExtension<PMProject_Extension>();
Caches[typeof(PMProject)].SetValue<PMProject_Extension.usrLGRevisionID>(projects, row.RevisionID);
Caches[typeof(PMProject)].Persist(projects, PXDBOperation.Update);
continue;
}
}
}
}
Best answer by Naveen Boga
View original