Skip to main content

PXRedirectRequiredException Behaviour

  • October 28, 2024
  • 1 reply
  • 143 views

Forum|alt.badge.img+8

Hello community,

 

I have been experiencing something with PXRedirectRequiredException and am wondering if this is intended behaviour.

I have an action which creates a Non-Conformance record from a Sales Order.

For the purpose of traceability, I added a custom field to display the NCR number.

doc = gilMaint.ISORecords.Insert(doc);//Insert the record
doc.SOOrderNbr = order.OrderNbr;
doc.CustomerID = order.CustomerID;
gilMaint.ISORecords.Update(doc);
gilMaint.Actions.PressSave();//Save the new record to generate a DocNumber through autonumbering

SOOrderISOExt orderExt = PXCache<SOOrder>.GetExtension<SOOrderISOExt>(order);//Find DAC extension
orderExt.UsrNCRNumber = doc.DocNumber;//Assign custom field value
orderEntry.Document.Update(order);
orderEntry.Actions.PressSave();//Save the Sales Order record

PXRedirectHelper.TryRedirect(gilMaint, PXRedirectHelper.WindowMode.New);//Redirect to the freshly created record to populate it.

When executing the action and the PXRedirectRequiredException being in the body of the method, the value does not populate, although whilst debugging the cache shows that the value was populated, in both the target DAC and the Sales Order.

After refreshing the browser the value is still null.

When I remove the redirect line and add it to the IEnumerable of the action

 protected virtual IEnumerable createNCRAction(PXAdapter adapter)
{
List<SOOrder> list = new List<SOOrder>();
foreach (SOOrder order in adapter.Get<SOOrder>())
{
list.Add(order);
}

Base.Actions.PressSave();

var document = Base.Document.Current;
PXLongOperation.StartOperation(Base, delegate ()
{
CreateNCR(document);
});

var gilMaint = PXGraph.CreateInstance<GilcrestMaint>();
var sOOrder = Base.Document.Current;
SOOrderISOExt orderExt = sOOrder.GetExtension<SOOrderISOExt>();
var rec = gilMaint.ISORecords.Search<ISORecord.docNumber>(orderExt.UsrNCRNumber);

throw new PXRedirectRequiredException(gilMaint, true, nameof(CreateNCR))
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};


}

This works as intended and fills the value, although the screen has to be refreshed.

Is this how the PXRedirectRequiredException is meant to work, or should it also work within the method after the base graph is saved.

 

Aleks

1 reply

Forum|alt.badge.img+8
  • Author
  • Captain II
  • October 30, 2024

I put the redirect after ts.Complete();

 

This populated the value, executed the Long Operation, and performed the redirection as expected.