I have a very strange issue that feels like a bug. I am iterating through a list of SOOrders and then using the following line to set the current order as the Document.Current:
foreach (SOOrder order in orders)
{
orderGraph.Document.Current = orderGraph.Document.Search<SOOrder.orderType, SOOrder.orderNbr>(order.OrderType, order.OrderNbr);
// ...
}
However, when performing this search for any order type that is not the Default Sales Order Type on SO Preferences, the value returned by the search is null.
This gets deeper. I tested the following code with a simple action on SOOrderEntry:
public PXAction<SOOrder> ActionName;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "ActionName")]
public virtual void actionName()
{
SOOrder order = Base.Document.Search<SOOrder.orderType, SOOrder.orderNbr>(Base.Document.Current.OrderType, Base.Document.Current.OrderNbr);
throw new PXException($"{order.OrderType} {order.OrderNbr}");
}
Notice I’m performing the search in the Base graph. This works successfully for any order type.
I tested the following code (slightly altered to use a new graph instance):
public PXAction<SOOrder> ActionName;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "ActionName")]
public virtual void actionName()
{
var orderGraph = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder order = orderGraph.Document.Search<SOOrder.orderType, SOOrder.orderNbr>(Base.Document.Current.OrderType, Base.Document.Current.OrderNbr);
throw new PXException($"{order.OrderType} {order.OrderNbr}");
}
For any order type that is not the Default Sales Order Type on SO Preferences, the exception is an unhandled object reference error (meaning the order is null), while an order of the default type successfully displays the type and order number.
If this is NOT a bug, could someone explain to me why this is happening and what to do instead?