0
votes

I have one custom screen with some values and a button, based on some logic I want to open Sales Order and set order type. Am able to do that only for SO order type as SO is set as default in the preferences screen. My question is, how I can open Sales Order and set "IN" or "RM" as default.

SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);

i also tried with below code and it is also working only for SO type but, it is selecting first order as default.

SOOrderEntry docgraph = PXGraph.CreateInstance<SOOrderEntry>();
docgraph.Document.Current = docgraph.Document.Search<SOOrder.orderType>(SOOrderTypeConstants.SalesOrder);
throw new PXRedirectRequiredException(docgraph, true, "Order") { Mode = PXBaseRedirectException.WindowMode.Same };
1

1 Answers

2
votes

docgraph.Document.Search<SOOrder.orderType>(SOOrderTypeConstants.SalesOrder); this code will return you first Order of SalesOrder type. Instead of this you can do the following:
1. Create an instance of SalesOrder.
2. Set the OrderType of the SalesOrder to the one you need.
3. Set docgraph.Document.Current to that SalesOrder.

Your code will be like the following(may some changes will be required):

SOOrderEntry docgraph = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder newOrder = docgraph.Document.Insert();//create new Order
newOrder.OrderType = "IN"; // set the OrderType to the one you need.For example "IN"
newOrder = docgrapg.Document.Update(newOrder);//  update the order
docgraph.Document.Current = newOrder;// set your order as the current order of the BLC
throw new PXRedirectRequiredException(docgraph, true, "Order") { Mode = PXBaseRedirectException.WindowMode.Same };