getting an error "Any unsaved changes will be discarded." on any action including Add New Record, First, Previous ... even after screen data is saved.
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.
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.
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;
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.
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:
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;
//Not good foreach (PMCashflowProjectionSchedule cashflowProjectionSchedules in this.CashflowProjectionSchedules.Select())
// use e.Row instead if you want to access a row
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
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;
@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
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
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.
PXUIField(DisplayName = "Revision")] public virtual String RevisionID {get; set;} #endregion
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 “+”.
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.
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;
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); } } }
@aaghaei Thanks for sharing the code, will take a look and get back you
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.
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.