Solved

My popup keeps getting called (loop)

  • 14 December 2022
  • 5 replies
  • 127 views

Userlevel 6
Badge +3

When a user does not enter a serial number on the Support Entry screen of the portal, I want to popup a dialog box.  I can set an error on the field, but the user won’t see the message unless they mouse over the red x.  I want them to get a popup with instructions to make it clearer to the user.

The popup works.  But it keeps getting called in a loop if I put e.Cancel = true in the event.

If I use Sender.RaiseExeptionHandling, the screen functions properly and if you mouse over the error on the field, it shows my information properly.

If I remove the e.Cancel = true;, the popup occurs once, but the record is still saved...that’s not good.

(DAC shown below...I think that is the issue)

 

       protected virtual void CRCase_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
if (e.Row == null)
{
return;
}
CRCase caseRow = (CRCase)e.Row;

CRCaseSSGPortalExt cRCaseExt = PXCache<CRCase>.GetExtension<CRCaseSSGPortalExt>(caseRow);

if (cRCaseExt.UsrSerialNbr == null)
{

//sender.RaiseExceptionHandling<CRCaseSSGPortalExt.usrSerialNbr>(caseRow, null, new PXSetPropertyException(ISOMessages.PopupSerialNumber, PXErrorLevel.Error));

WebDialogResult result = dummyBaccount.Ask(ActionsMessages.Warning, PXMessages.LocalizeFormatNoPrefix(ISOMessages.PopupSerialNumber),
MessageButtons.OK, MessageIcon.Error, true);

//checking answer
if (result != WebDialogResult.OK) return;

//e.Cancel = true;
}
}

The DAC for the field is as follows:

       #region UsrSerialNbr
        [PXDBString(100, IsUnicode = true)]
        [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "Serial Number", Required = true)]
        public virtual string UsrSerialNbr { get; set; }
        public abstract class usrSerialNbr : IBqlField
        {
        }
        #endregion

If I remove (PersistingCheck = PXPersistingCheck.Nothing) from the DAC, and remove e.Cancel = true, everything works the way it should.

However, I get an acuminator warning

Should I just ignore the warning?

I don’t think I can ignore the warning.  If I try to re-open a closed case, there is an error on that field if it was previously closed without a serial number.  AND, you cannot edit the field because the case is closed.

 

icon

Best answer by Joe Schmucker 15 December 2022, 19:18

View original

5 replies

Userlevel 5
Badge +2

@joe21 

I would recommend not removing the PXPersistingCheck property value.

Have you tried using a direct PXException instead?

       protected virtual void CRCase_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
if (e.Row == null)
{
return;
}
CRCase caseRow = (CRCase)e.Row;

CRCaseSSGPortalExt cRCaseExt = PXCache<CRCase>.GetExtension<CRCaseSSGPortalExt>(caseRow);

if (cRCaseExt.UsrSerialNbr == null)
{
throw new PXException(ActionsMessages.Warning);
}
}

 

Userlevel 6
Badge +3

@Fernando Amadoz 

I did that and it works.

//sender.RaiseExceptionHandling<CRCaseSSGPortalExt.usrSerialNbr>(caseRow, null, new PXSetPropertyException(ISOMessages.PopupSerialNumber, PXErrorLevel.Error));

However, I want the popup to show to really clarify to the user that they can enter TBD if they don’t know the serial number.  

If I could find a way to use e.Cancel without having the popup loop, that would be ideal.

Userlevel 7
Badge +8

@joe21 I had a similar issue but for a different use case. As you know, If the keyboard's delete key is hit and a field is not in edit mode, Acumatica deletes the whole row in grids. In Project Cost Projection  I wanted user confirmation and if No was selected undo the change. I guess you can slightly edit the code for the Persisting Event and Custom Field Ext validation and dialog Message Buttons. Hope this helps.

 

protected virtual void PMCostProjectionLine_RowDeleting(PXCache cache, PXRowDeletingEventArgs e, PXRowDeleting BaseHandler)
{
if (e.Row == null) return;

PMCostProjectionLine row = e.Row as PMCostProjectionLine;

if (Base.Details.Ask(HCLPMMessages.Confirmation, HCLPMMessages.DeleteCostProjectionLine, MessageButtons.YesNo) != WebDialogResult.Yes)
{
e.Cancel = true;
return;
}

BaseHandler?.Invoke(cache, e);
}

 

Userlevel 7
Badge +8

@joe21 I did a quick revision here. Hopefully, it works or helps.

// Verify when persisting:
protected virtual void CRCase_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting BaseHandler)
{
if (e.Row == null) return;

CRCase caseRow = e.Row as CRCase;
CRCaseSSGPortalExt caseExt = PXCache<CRCase>.GetExtension<CRCaseSSGPortalExt>(caseRow);

if (caseExt.UsrSerialNbr == null)
{
Base.Case.Ask("Message", MessageButtons.OK);
e.Cancel = true;
return;
}

BaseHandler?.Invoke(cache, e);
}

// or you can write a persist delegate like (I have not tested this but should work):
public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate del)
{
if (Base.Case.Current != null)
{
object serialNbr = Base.Case.Current.GetExtension<CRCaseSSGPortalExt>().UsrSerialNbr;
if (serialNbr == null)
{
Base.Case.Cache.RaiseFieldVerifying<CRCaseSSGPortalExt.usrSerialNbr>(Base.Case.Current, ref serialNbr);
Base.Case.Ask("Message", MessageButtons.OK);
return;
}
}

del();
}

 

Userlevel 6
Badge +3

Thanks @Fernando Amadoz and @aaghaei for taking the time to help me out.

The root of the issue is the fact that we changed a field to being required.  I wrote a SQL script to update all null values in the serial number field.  This solved the issue of bringing up old records that had nulls.

Because I am testing for a null value in a field in the row persisting event and every time the popup returns back to the event, I really cannot get around the looping of the popup.  I tried both of your options but if I manually cancel the row in code, it will loop.  

I ended up using my code without the cancel option.  Setting the field to required without setting the persisting check handles the display of the required field error on the page, while still allowing the popup to be displayed.

Thanks for all your help.  I’ve resolved this one.

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