I have created a customization to convert a PO created from the Requisitions screen to a Project-Drop Ship PO. It would be nice if that was an option on the requisitions screen, but it is not.
When you create an order from the requisitions screen, it creates a standard PO. I have an action on the Purchase Orders screen to convert it to a Project-Drop Ship PO. The code is hacky, but it works.
After the action completes, the PO screen is cleared ready for a new PO. I want to redisplay the screen with the PO that was just converted. It is a pain for the user to have to lookup the PO again after it was converted.
I’ve tried MANY ways to try to do a PXRedirect back to the PO screen but I cannot quite get it working.
If I do the convert, my current redirect sort of works. The details grid gets populated, but the header fields do not. If you click Cancel, it fills the fields. I don’t know how I can click Cancel programmatically after the redirect.
This is what the screen looks like after the redirect:

After clicking cancel, everything looks good:

Here is the code for my action. You can see I’ve tried a plethora of options. The one that is not commented out is the only one that even slightly works.
public PXAction<POOrder> ConvertToPDS;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Convert To Project Drop-Ship", Enabled = true)]
protected virtual void convertToPDS()
{
//try
//{
// Get the current order from the cache.
POOrder row = Base.Document.Current;
string orderNbr = row.OrderNbr;
RQRequisitionOrder rQRequisitionOrder = SelectFrom<RQRequisitionOrder>.Where<RQRequisitionOrder.reqNbr.IsEqual<@P.AsString>>.View.Select(Base, row.RQReqNbr);
if (rQRequisitionOrder != null)
{
RQRequisition requisition = SelectFrom<RQRequisition>.Where<RQRequisition.reqNbr.IsEqual<@P.AsString>>.View.Select(Base, row.RQReqNbr);
if (requisition != null)
{
SCGCRQRequisitionExt ext = requisition.GetExtension<SCGCRQRequisitionExt>();
if (ext != null)
{
foreach (POLine poLine in SelectFrom<POLine>.Where<POLine.orderNbr.IsEqual<@P.AsString>
.And<POLine.orderType.IsEqual<@P.AsString>>>.View.Select(Base, row.OrderNbr, row.OrderType))
{
//InventoryItem invItem = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<@P.AsInt>>.View.Select(Base, poLine.InventoryID);
//if (invItem == null) return;
RQRequisitionLine rQRequestLine = SelectFrom<RQRequisitionLine>
.Where<RQRequisitionLine.reqNbr.IsEqual<@P.AsString>
.And<RQRequisitionLine.lineNbr.IsEqual<@P.AsInt>>>.View.Select(Base, poLine.RQReqNbr, poLine.RQReqLineNbr);
PXDatabase.Update<POLine>(
new PXDataFieldAssign(typeof(POLine.projectID).Name, PXDbType.Int, ext.UsrProjectID),
new PXDataFieldAssign(typeof(POLine.expenseAcctID).Name, PXDbType.Int, rQRequestLine.ExpenseAcctID),
new PXDataFieldAssign(typeof(POLine.expenseSubID).Name, PXDbType.Int, rQRequestLine.ExpenseSubID),
new PXDataFieldAssign(typeof(POLine.taskID).Name, PXDbType.Int, ext.UsrProjectTask),
new PXDataFieldAssign(typeof(POLine.orderType).Name, PXDbType.NVarChar, "PD"),
new PXDataFieldAssign(typeof(POLine.dropshipReceiptProcessing).Name, PXDbType.NVarChar, "R"),
new PXDataFieldAssign(typeof(POLine.dropshipExpenseRecording).Name, PXDbType.NVarChar, "B"),
new PXDataFieldAssign(typeof(POLine.lineType).Name, PXDbType.NVarChar, "PG"),
new PXDataFieldRestrict(typeof(POLine.orderNbr).Name, PXDbType.NVarChar, row.OrderNbr),
new PXDataFieldRestrict(typeof(POLine.lineNbr).Name, PXDbType.NVarChar, poLine.LineNbr),
new PXDataFieldRestrict(typeof(POLine.orderType).Name, PXDbType.NVarChar, row.OrderType));
}
//PXDatabase.Update<POLine>(
//new PXDataFieldAssign(typeof(POLine.projectID).Name, PXDbType.Int, ext.UsrProjectID),
//new PXDataFieldAssign(typeof(POLine.taskID).Name, PXDbType.Int, ext.UsrProjectTask),
//new PXDataFieldAssign(typeof(POLine.orderType).Name, PXDbType.NVarChar, "PD"),
//new PXDataFieldRestrict(typeof(POLine.orderNbr).Name, PXDbType.NVarChar, row.OrderNbr),
// new PXDataFieldRestrict(typeof(POLine.orderType).Name, PXDbType.NVarChar, row.OrderType));
PXDatabase.Update<RQRequisitionOrder>(
new PXDataFieldAssign(typeof(RQRequisitionOrder.orderType).Name, PXDbType.NVarChar, "PD"),
new PXDataFieldRestrict(typeof(RQRequisitionOrder.orderNbr).Name, PXDbType.NVarChar, row.OrderNbr));
PXDatabase.Update<POOrder>(
new PXDataFieldAssign(typeof(POOrder.projectID).Name, PXDbType.Int, ext.UsrProjectID),
new PXDataFieldAssign(typeof(POOrder.dropshipReceiptProcessing).Name, PXDbType.NVarChar, "R"),
new PXDataFieldAssign(typeof(POOrder.dropshipExpenseRecording).Name, PXDbType.NVarChar, "B"),
new PXDataFieldAssign(typeof(POOrder.shipDestType).Name, PXDbType.NVarChar, "P"),
new PXDataFieldAssign(typeof(POOrder.orderType).Name, PXDbType.NVarChar, "PD"),
new PXDataFieldAssign(typeof(POOrder.hold).Name, PXDbType.Int, 1),
new PXDataFieldAssign(typeof(POOrder.status).Name, PXDbType.NVarChar, "H"),
new PXDataFieldAssign(typeof(POOrder.approved).Name, PXDbType.Int, 0),
new PXDataFieldRestrict(typeof(POOrder.orderNbr).Name, PXDbType.NVarChar, row.OrderNbr),
new PXDataFieldRestrict(typeof(POOrder.orderType).Name, PXDbType.NVarChar, row.OrderType));
Base.Actions.PressSave();
//Base.Clear();
//Base.Actions.PressCancel();
//var graph = PXGraph.CreateInstance<POOrderEntry>();
//graph.Document.Current = Base.Document.Current;
//if (graph.Document.Current != null)
//{
// graph.Document.Current.OrderType = "PD";
// throw new PXRedirectRequiredException(graph, false, "PO Order Entry");
//}
//loops a dialog
//var graph = PXGraph.CreateInstance<POOrderEntry>();
//POOrder order = new POOrder();
//order.OrderNbr = orderNbr;
//order.OrderType = "PD";
//graph.Document.Update(order);
//throw new PXRedirectRequiredException(graph, true, "PO Order Entry");
//var graph = PXGraph.CreateInstance<POOrderEntry>();
//POOrder newOrder = new POOrder();
//newOrder.OrderNbr = orderNbr;
//newOrder.OrderType = "PD";
////graph.Document.Current = newOrder;
//graph.Document.Update(newOrder);
//throw new PXRedirectRequiredException(graph, false, "PO Order");
//sort of works
//redirects but leaves fields in header empty
//If I click cancel, it fills the fields
var graph = PXGraph.CreateInstance<POOrderEntry>();
graph.Document.Current = new POOrder();
graph.Document.Current.OrderNbr = orderNbr;
graph.Document.Current.OrderType = "PD";
//graph.Document.UpdateCurrent();
throw new PXRedirectRequiredException(graph, false, "PO Order Entry");
}
}
}
}
The pertinent code starts on line 103.
Any ideas on what I might be doing wrong?