Solved

getting an error "Any unsaved changes will be discarded." on any action including Add New Record, First, Previous ... even after screen data is saved.

  • 14 December 2021
  • 11 replies
  • 441 views

Userlevel 7
Badge +9

I have created a new “FormTab.master” form that I have two problems with it. The form works fine when I take away the tab from the form but when add it back the problems persist.

  1. When I Click Add New Record, not sure the form doesn’t reset the fields. The fields whithout default value, should be empty but are not.
  2. Even if the data is saved (I confirmed through both DB and Primary List) after clicking on Save, no matther what action I trigger (Add New, First, Last ...) I get an error that "Any unsaved changes will be discarded."

For claification the header PKs are ProjectID and RevisionID and detail PKs are thesame fields plus TranPeriodID.

 

Here is my Graph:

    public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
{
[PXViewName("Projects Cashflow Projections")]
public PXSelect<PMCashflowProjection> CashflowProjections;

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

protected void PMCashflowProjection_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
PMCashflowProjection cashflowProjections = CashflowProjections.Current;

if (cashflowProjections == null)
{
return;
}
else
{
#region Set Projection Visibility
bool OriginalIsEnabled = (cashflowProjections.OriginalIsLocked == true) ? false : true;
bool RevisionIsEnabled = (cashflowProjections.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)
{
PMCashflowProjection cashflowProjections = CashflowProjections.Current;

if (cashflowProjections == null)
{
return;
}
else
{
#region Calculate Roll-up Fields
cashflowProjections.OriginalValueRollup = 0m;
cashflowProjections.RevisedValueRollup = 0m;

foreach (PMCashflowProjectionSchedule cashflowProjectionSchedules in this.CashflowProjectionSchedules.Select())
{
cashflowProjections.OriginalValueRollup += cashflowProjectionSchedules.OriginalValue.GetValueOrDefault();
cashflowProjections.RevisedValueRollup += cashflowProjectionSchedules.RevisedValue.GetValueOrDefault();
}

CashflowProjections.Update(cashflowProjections);

CashflowProjectionSchedules.View.RequestRefresh();
#endregion
}


if (cashflowProjections == null)
{
return;
}
else
{
#region Set Projection Schedule Visibility
bool OriginalIsEnabled = (cashflowProjections.OriginalIsLocked == true) ? false : true;
bool RevisionIsEnabled = (cashflowProjections.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
}
}
}

 

and here is my ASPX

<%@ Page Language="C#" MasterPageFile="~/MasterPages/FormTab.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="PM904000.aspx.cs" Inherits="Page_PM904000" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPages/FormTab.master" %>

<asp:Content ID="cont1" runat="Server" ContentPlaceHolderID="phDS">
<px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%" TypeName="LGCustom.PMCashflowProjectionEntry" PrimaryView="CashflowProjections" BorderStyle="NotSet">
<CallbackCommands>

</CallbackCommands>
</px:PXDataSource>
</asp:Content>

<asp:Content ID="cont2" runat="Server" ContentPlaceHolderID="phF">
<px:PXFormView ID="form" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" Height="150px" AllowAutoHide="true" DataMember="CashflowProjections" Caption="" FilesIndicator="True" NoteindIcator="True" DefaultControlID="edProjectID">
<Template>
<px:PXLayoutRule runat="server" ID="PXLayoutRule1" StartColumn="True" ControlSize="XM" LabelsWidth ="SM" ></px:PXLayoutRule>
<px:PXSegmentMask runat="server" ID="edBranchID" DataField="BranchID" AutoCallBack="True" />
<px:PXSegmentMask runat="server" ID="edProjectID" DataField="ProjectID" />
<px:PXSelector runat="server" ID="edRevisionID" DataField="RevisionID" AutoRefresh="True" />
<px:PXCheckBox runat="server" ID="chkOriginalIsLocked" DataField="OriginalIsLocked" CommitChanges="True" ></px:PXCheckBox>
<px:PXCheckBox runat="server" ID="chkRevisionIsLocked" DataField="RevisionIsLocked" CommitChanges="True" ></px:PXCheckBox>

<px:PXNumberEdit runat="server" ID="edOriginalValueRollup" DataField="OriginalValueRollup" />
<px:PXNumberEdit runat="server" ID="edRevisedValueRollup" DataField="RevisedValueRollup" />
</Template>
</px:PXFormView>
</asp:Content>

<asp:Content ID="cont3" runat="Server" ContentPlaceHolderID="phG">
<px:PXTab ID="tab" runat="server" DataSourceID="ds" DataMember="CashflowProjectionSchedules" Width="100%" Height="300px" AllowAutoHide="false">
<Activity HighlightColor="" SelectedColor="" Width="" Height=""></Activity>
<Items>
<px:PXTabItem Text="Schedule" Visible="true">
<Template>
<px:PXGrid ID="CashflowProjectionSchedulesGrid" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" Height="300px" SkinID="DetailsInTab" OnRowDataBound="grid_RowDataBound">
<Levels>
<px:PXGridLevel DataMember="CashflowProjectionSchedules">
<RowTemplate>

</RowTemplate>

<Columns>
<px:PXGridColumn DataField="ProjectID" Width="80" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="RevisionID" Width="80" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="TranDate" AutoCallBack="True" Width="70" ></px:PXGridColumn>
<px:PXGridColumn DataField="TranPeriodID" CommitChanges="True" Width="70" ></px:PXGridColumn>
<px:PXGridColumn DataField="FinPeriodID" AutoCallBack="True" Width="70" ></px:PXGridColumn>

<px:PXGridColumn DataField="OriginalPercent" Width="80" CommitChanges="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="OriginalCost" Width="100" CommitChanges="True" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="OriginalFee" Width="100" CommitChanges="True" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="OriginalValue" Width="100" CommitChanges="True" AutoCallBack="True" ></px:PXGridColumn>

<px:PXGridColumn DataField="RevisedPercent" Width="80" CommitChanges="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="RevisedCost" Width="100" CommitChanges="True" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="RevisedFee" Width="100" CommitChanges="True" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="RevisedValue" Width="100" CommitChanges="True" AutoCallBack="True" ></px:PXGridColumn>

<px:PXGridColumn DataField="Comment" Width="300" ></px:PXGridColumn>
<px:PXGridColumn DataField="BranchID" Width="140" AutoCallBack="True" ></px:PXGridColumn>
<px:PXGridColumn DataField="RevisionDate" AutoCallBack="True" Width="70" ></px:PXGridColumn>
</Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" />
</px:PXGrid>
</Template>
</px:PXTabItem>
</Items>
<AutoSize Container="Window" Enabled="True" MinHeight="300" MinWidth="300" ></AutoSize>
</px:PXTab>
</asp:Content>

 

icon

Best answer by Naveen Boga 14 December 2021, 19:49

View original

11 replies

Userlevel 7
Badge +17

Hi @aaghaei  It is NOT recommended to write Update the values in Row_Selected event.
Please remove from RowSelected event and move this logic to appropriate event and check once.

 

 

Userlevel 7
Badge +5

I think it’s that line of code in the PMCashflowProjectionSchedule_RowSelected:

 CashflowProjections.Update(cashflowProjections);

Basically, RowSelected event is executed every time the request is sent from the client to the server. 

So once you click any buttons the update is happening and that means you have unsaved changes. 

 

Couple of recommendations here:

  1. You should not really use the Current in the events. Use e.Row instead 
    // Not good 
    protected void PMCashflowProjection_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
    PMCashflowProjection cashflowProjections = CashflowProjections.Current;


    //Correct:
    protected void PMCashflowProjection_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
    PMCashflowProjection cashflowProjections = (PMCashflowProjection) e.Row;

     

  2.  You should not really select from the same view that you have an event for. The event is already triggered for a single row of the view. 
     protected void PMCashflowProjectionSchedule_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
    // ...

    //Not good
    foreach (PMCashflowProjectionSchedule cashflowProjectionSchedules in this.CashflowProjectionSchedules.Select())

    // use e.Row instead if you want to access a row

     

  3. In general the RowSelected event is not designed for any type of values assignments. As far as I can tell, you are trying to calculate some totals on the screen. For that you can use PXFormula approach. See T2xx trainings
Userlevel 7
Badge +17

Hi @aaghaei  Here is the code that I have modified a bit.

Again, As said above, please remove value assignment logic and .Update code from RowSelected event.

  public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
{
[PXViewName("Projects Cashflow Projections")]
public PXSelect<PMCashflowProjection> CashflowProjections;

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

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

//PMCashflowProjection cashflowProjections = CashflowProjections.Current;

if (cashflowProjections == null)
{
return;
}
else
{
#region Set Projection Visibility
bool OriginalIsEnabled = (cashflowProjections.OriginalIsLocked == true) ? false : true;
bool RevisionIsEnabled = (cashflowProjections.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 cashflowProjections = CashflowProjections.Current;

// Move this block from here

//if (cashflowProjections == null)
//{
// return;
//}
//else
//{

//#region Calculate Roll-up Fields
//cashflowProjections.OriginalValueRollup = 0m;
//cashflowProjections.RevisedValueRollup = 0m;

//foreach (PMCashflowProjectionSchedule cashflowProjectionSchedules in this.CashflowProjectionSchedules.Select())
//{
// cashflowProjections.OriginalValueRollup += cashflowProjectionSchedules.OriginalValue.GetValueOrDefault();
// cashflowProjections.RevisedValueRollup += cashflowProjectionSchedules.RevisedValue.GetValueOrDefault();
//}

//CashflowProjections.Update(cashflowProjections);

//CashflowProjectionSchedules.View.RequestRefresh();
// #endregion
// }


if (cashflowProjections == null)
{
return;
}
else
{
#region Set Projection Schedule Visibility
bool OriginalIsEnabled = (cashflowProjections.OriginalIsLocked == true) ? false : true;
bool RevisionIsEnabled = (cashflowProjections.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
}
}
}
}

 

Userlevel 7
Badge +9

@Naveen B  and @dnaumov thanks for the response. by taking away this part of code the error is gone but still when I click on Add New the form is not reset. The reason I had added the parent update from child is that I have a couple of total fields in header that I want to refresh as soon as childs are changing. Initially I had used the SumCalc on Child to update parent 

        [PXFormula(typeof(Add<IsNull<originalCost, decimal0>, IsNull<originalFee, decimal0>>), 
typeof(SumCalc<PMCashflowProjection.originalValueRollup>))]

but didn’t work. I did some search and I saw a post that I Acumatica Support had mentioned this is a known issue and the method I used was suggested. So, Can you please advise what should I do to update the header on the fly when child changes?

I have another issue that I just noticed. When I Save Header and then start adding items everything is fine but if I enter header data and immediately start adding items I get “Error: An error occurred during processing of the field Revision: Error: 'Revision' cannot be found in the system.” Revision is a Key field in my child DAC as below

        #region RevisionID  
public abstract class revisionID : PX.Data.BQL.BqlString.Field<revisionID> { }
protected String _RevisionID;
[PXDBString(30, IsKey = true, InputMask = "0000")]
[PXDBDefault(typeof(PMCashflowProjection.revisionID))]
[PXSelector(typeof(Search<PMCashflowProjection.revisionID, Where<PMCashflowProjection.projectID, Equal<Current<PMCashflowProjection.projectID>>>, OrderBy<Desc<PMCashflowProjection.revisionID>>>))]
[PXUIField(DisplayName = "Revision", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = false, Visible = true)]
public virtual String RevisionID {get; set;}
#endregion

 

Your help is much appreciated

 

Userlevel 7
Badge +17

Hi @aaghaei  Below article will help you get the sum values from child to parent.

https://asiablog.acumatica.com/2019/06/calculating-grid-totals-on-a-form.html

 

For your second question: I’m assuming this above Revision ID field from the child DAC.

If it is a child DAC, it is not required to show on the UI and it is only for maintaining the relation between parent and child. Have a DAC field like below and verify.

 

 #region RevisionID  
public abstract class revisionID : PX.Data.BQL.BqlString.Field<revisionID> { }
protected String _RevisionID;
[PXDBString(30, IsKey = true, InputMask = "0000")]
[PXDBDefault(typeof(PMCashflowProjection.revisionID))]

[PXUIField(DisplayName = "Revision")]
public virtual String RevisionID {get; set;}
#endregion

 

 

Userlevel 7
Badge +9

Thanks @Naveen B for the help. Everything works fine now. The only remainin issue is that Add New “+” of the main form doesn’t rest the form and fields. It shows the values from last record I have created when I click on “+”.

Userlevel 7
Badge +17

Hi @aaghaei  I’m not clear with the issue. Could you please elaborate and share some screenshots of the issue. Also, please share the updated code.

Userlevel 7
Badge +9

Hi @Naveen B 

I have attached a very short video here in zip file. When I click on Add New, I expect the form to be initialized and fiedls like as Project (Do no have default values asigned) presented as empty. Also I expect the grid also reset to show no data. Here is my complete graph.

    public class PMCashflowProjectionEntry : PXGraph<PMCashflowProjectionEntry, PMCashflowProjection>
{

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

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

#region Event Handlers
protected void PMCashflowProjection_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
PMCashflowProjection cashflowProjections = e.Row as PMCashflowProjection;

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

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

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

if (cashflowProjections != null)
{
#region Set Projection Visibility
bool originalIsEnabled = (cashflowProjections.OriginalIsLocked == true) ? false : true;
bool revisionIsEnabled = (cashflowProjections.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 cashflowProjectionSchedules = e.Row as PMCashflowProjectionSchedule;

if (cashflowProjectionSchedules != null)
{
PMCashflowProjection cashflowProjections = CashflowProjections.Current;

if (cashflowProjections != null)
{
#region Set Projection Schedule Visibility
bool originalIsEnabled = (cashflowProjections.OriginalIsLocked == true) ? false : true;
bool revisionIsEnabled = (cashflowProjections.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
}

Here is screenshot before clicking on Add New

 

and here is screenshot after clicking on Add New

Thanks

Userlevel 7
Badge +17

@aaghaei  Thanks for sharing the code, will take a look and get back you

Userlevel 7
Badge +17

Hi @aaghaei  I don’t see any issues with the Graph code, I’m assuming that the issue your DAC files.

Can you please share your DAC files here.

Userlevel 7
Badge +9

Hi @Naveen B . You are right. The issue was in paren/child DAC relation setting for the grid which I fixed it and now Add New resets the grid. The only field which is not resetting is “ProjectID” in the header DAC that I have copied its properties below. It is not really a big deal but that will be great if I can reset this field as well.

        #region ProjectID
public abstract class projectID : PX.Data.BQL.BqlInt.Field<projectID> { }
protected Int32? _ProjectID;
[Project(IsKey = true)]
[PXForeignReference(typeof(Field<PMCashflowProjection.projectID>.IsRelatedTo<PMProject.contractID>))]
[PXParent(typeof(Select<PMProject, Where<PMProject.contractID, Equal<Current<PMCashflowProjection.projectID>>>>))]
[PXUIField(DisplayName = "Project", Visibility = PXUIVisibility.SelectorVisible, Required = true, Enabled = true, Visible = true)]
public virtual Int32? ProjectID
{
get
{
return this._ProjectID;
}
set
{
this._ProjectID = value;
}
}
#endregion

 

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