Solved

Not able to update another table first time. But second time it works.

  • 22 December 2021
  • 8 replies
  • 134 views

Userlevel 7
Badge +8

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

 

icon

Best answer by Naveen Boga 25 December 2021, 09:56

View original

8 replies

Userlevel 7
Badge +17

Hi @aaghaei  Are you trying to update the flag like below please confirm?

  • If (revisions.RevisionID != row.RevisionID), you want to set IsCurrent = false and if both revisions are matching then you wanted to update IsCurrent = true right?

If yes, can you please share you complete graph code file here.

Userlevel 7
Badge +8

Hi @Naveen B,

For the first part that in CashflowProjection yes assuming the selected projection IsCurrent flag is set to true yes but this is not my problem. My problem is I want to update a field in PMProject Extension to set its value equal to current projection revisionID again assuming the selected projection IsCurrent flag is true. My problem is updating PMProject that doesn’t happen first time.

Here is my graph:

using PX.Data;
using PX.Objects.PM;

namespace LGCustom
{
//**************************************** PMCashflowProjectionEntry ****************************************//
public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
{

[PXViewName("Projects Cashflow Projections")]
public PXSelect<PMCashflowProjection> CashflowProjections;

public PXSelect<PMCashflowProjection,
Where<PMCashflowProjection.projectID, Equal<Current<PMCashflowProjection.projectID>>>> RevisionsFilter;

public PXSelect<PMCashflowProjectionSchedule,
Where<PMCashflowProjectionSchedule.projectID, Equal<Current<PMCashflowProjection.projectID>>,
And<PMCashflowProjectionSchedule.revisionID, Equal<Current<PMCashflowProjection.revisionID>>>>> CashflowProjectionSchedules;

public PXSelect<PMProject,
Where<PMProject.contractID, Equal<Current<PMCashflowProjection.projectID>>>> ProjectsFilter;


#region Event Handlers
protected void PMCashflowProjection_RevisionID_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
PMCashflowProjection row = e.Row as PMCashflowProjection;

if (row != null)
{
if (row.ProjectID != null)
{
if (row.RevisionID != null)
{
int padWidth = 4;
char padChar = '0';
string padRevisionID = row.RevisionID.PadLeft(padWidth, padChar);
row.RevisionID = padRevisionID;
//cashflowProjections.RevisionID = padRevisionID.Substring(padRevisionID.Length-padWidth, padWidth);
}
}
}
}


protected void PMCashflowProjection_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
PMCashflowProjection row = e.Row as PMCashflowProjection;

if (row != null)
{
// Validate whether Cashflow Schedule agrees to the total expected cashflow from the project.
if (row.OriginalValue != row.OriginalValueRollup)
{
throw new PXException(PMMessages_Extension.OriginalCashflowAllocationIsNotBalanced);
}

if (row.RevisedValue != row.RevisedValueRollup)
{
throw new PXException(PMMessages_Extension.RevisedCashflowAllocationIsNotBalanced);
}

// 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);
//CashflowProjections.Update(revisions);
}
}
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.
//RevisionsFilter.View.RequestRefresh();
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;
}
}
}
}


protected void PMCashflowProjection_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
PMCashflowProjection row = e.Row as PMCashflowProjection;

if (row != null)
{
#region Set Projection Visibility
bool originalIsEnabled = (row.OriginalIsLocked == true) ? false : true;
bool revisionIsEnabled = (row.RevisionIsLocked == true) ? false : true;

PXUIFieldAttribute.SetEnabled<PMCashflowProjection.originalCost>(cache, null, originalIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjection.originalFee>(cache, null, originalIsEnabled);

PXUIFieldAttribute.SetEnabled<PMCashflowProjection.revisedCost>(cache, null, revisionIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjection.revisedFee>(cache, null, revisionIsEnabled);
#endregion
}
}


protected void PMCashflowProjectionSchedule_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{

PMCashflowProjectionSchedule row = e.Row as PMCashflowProjectionSchedule;

if (row != null)
{
PMCashflowProjection parent = CashflowProjections.Current;

if (parent != null)
{
#region Set Projection Schedule Visibility
bool originalIsEnabled = (parent.OriginalIsLocked == true) ? false : true;
bool revisionIsEnabled = (parent.RevisionIsLocked == true) ? false : true;

PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.originalPercent>(cache, null, originalIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.originalCost>(cache, null, originalIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.originalFee>(cache, null, originalIsEnabled);

PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.revisedPercent>(cache, null, revisionIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.revisedCost>(cache, null, revisionIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.revisedFee>(cache, null, revisionIsEnabled);
#endregion
}
}
}
#endregion
}
}

 

Userlevel 7
Badge +8

@Naveen B any though on this issue. All I want to do is to update a field in PMProject Ext from the Cashflow Projection assuming the status of this cashflow is set to Current.

Userlevel 7
Badge +17

Hi @aaghaei  I have re-write the code for updating the fields. Please find the code below.

Please verify and let me know if any queries.

 

  public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
{

[PXViewName("Projects Cashflow Projections")]
public PXSelect<PMCashflowProjection> CashflowProjections;

public PXSelect<PMCashflowProjection,
Where<PMCashflowProjection.projectID, Equal<Current<PMCashflowProjection.projectID>>>> RevisionsFilter;

public PXSelect<PMCashflowProjectionSchedule,
Where<PMCashflowProjectionSchedule.projectID, Equal<Current<PMCashflowProjection.projectID>>,
And<PMCashflowProjectionSchedule.revisionID, Equal<Current<PMCashflowProjection.revisionID>>>>> CashflowProjectionSchedules;

public PXSelect<PMProject,
Where<PMProject.contractID, Equal<Current<PMCashflowProjection.projectID>>>> ProjectsFilter;


#region Event Handlers
protected void PMCashflowProjection_RevisionID_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
PMCashflowProjection row = e.Row as PMCashflowProjection;

if (row != null)
{
if (row.ProjectID != null)
{
if (row.RevisionID != null)
{
int padWidth = 4;
char padChar = '0';
string padRevisionID = row.RevisionID.PadLeft(padWidth, padChar);
row.RevisionID = padRevisionID;
//cashflowProjections.RevisionID = padRevisionID.Substring(padRevisionID.Length-padWidth, padWidth);
}
}
}
}


//protected void PMCashflowProjection_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
//{

public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate del)
{
PMCashflowProjection row = PMCashflowProjection.Current;

if (row != null)
{
if (row.OriginalValue != row.OriginalValueRollup)
{
throw new PXException(PMMessages_Extension.OriginalCashflowAllocationIsNotBalanced);
}

if (row.RevisedValue != row.RevisedValueRollup)
{
throw new PXException(PMMessages_Extension.RevisedCashflowAllocationIsNotBalanced);
}
bool isCurrent = false;
if (row.IsCurrent == true)
{
foreach (PMCashflowProjection revisions in RevisionsFilter.Select())
{
if (revisions.RevisionID != row.RevisionID)
{
if (revisions.IsCurrent == true)
{
revisions.isCurrent = false;
RevisionsFilter.Update(revisions);
}
}
else
{
isCurrent = true;
}
}
}
else
{
foreach (PMCashflowProjection revisions in RevisionsFilter.Select())
{
if (revisions.IsCurrent == true)
{
isCurrent = true;
continue;
}
}
}
if (isCurrent != true)
{
throw new PXException(PMMessages_Extension.NoneOfTheCashflowRevisionsIsFlaggedAsCurrent);
}
foreach (PMProject projects in ProjectsFilter.Select())
{
if (projects.ContractID == row.ProjectID)
{
PMProject_Extension projectExt = projects.GetExtension<PMProject_Extension>();
projectExt.usrLGRevisionID = row.RevisionID;
ProjectsFilter.Cache.Update(projects);
}
}
}

del();
}


protected void PMCashflowProjection_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
PMCashflowProjection row = e.Row as PMCashflowProjection;

if (row != null)
{
#region Set Projection Visibility
bool originalIsEnabled = (row.OriginalIsLocked == true) ? false : true;
bool revisionIsEnabled = (row.RevisionIsLocked == true) ? false : true;

PXUIFieldAttribute.SetEnabled<PMCashflowProjection.originalCost>(cache, null, originalIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjection.originalFee>(cache, null, originalIsEnabled);

PXUIFieldAttribute.SetEnabled<PMCashflowProjection.revisedCost>(cache, null, revisionIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjection.revisedFee>(cache, null, revisionIsEnabled);
#endregion
}
}


protected void PMCashflowProjectionSchedule_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{

PMCashflowProjectionSchedule row = e.Row as PMCashflowProjectionSchedule;

if (row != null)
{
PMCashflowProjection parent = CashflowProjections.Current;

if (parent != null)
{
#region Set Projection Schedule Visibility
bool originalIsEnabled = (parent.OriginalIsLocked == true) ? false : true;
bool revisionIsEnabled = (parent.RevisionIsLocked == true) ? false : true;

PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.originalPercent>(cache, null, originalIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.originalCost>(cache, null, originalIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.originalFee>(cache, null, originalIsEnabled);

PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.revisedPercent>(cache, null, revisionIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.revisedCost>(cache, null, revisionIsEnabled);
PXUIFieldAttribute.SetEnabled<PMCashflowProjectionSchedule.revisedFee>(cache, null, revisionIsEnabled);
#endregion
}
}
}
#endregion
}

 

Userlevel 7
Badge +8

Thanks @Naveen B, the “.Current” is not an recognized object as you can see from the attached snip,

 

Userlevel 7
Badge +8

Hi @Naveen B, I couldn’t underestand why did you cahange my Persis Even code to Delete deligate but i figured out what was wrong in my code. with my code, When I was looping on revisions to update the project with current revision, I was not checking whether the revision is Current or not. I just had to check 

if (row.IsCurrent == true) then update the ProjectExt that I fixed. Thank you for your time. The issue is resolved.

Userlevel 7
Badge +17

Hi @aaghaei  Basically, we can handle both Persisting and Persisted events in Persist Delegate.

Sorry, the above code should be like below.

protected void PMCashflowProjection_RevisionID_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)

{

      PMCashflowProjection row = CashflowProjections.Current;

     //LOGIC

}

Anyways you have identified the root case and resolved and thanks a lot for sharing the update.

 

Userlevel 7
Badge +8

@Naveen B Thanks for the clarification. I’m new to Acumatica Cutomization and you have ABSOLUTELY been very helpful to me.

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