Retrieving order already open in UI

Discussions related to custom development with Select.
Post Reply
MattW
Posts: 46
Joined: Tue May 26, 2015 5:17 pm

Retrieving order already open in UI

Post by MattW »

We have a custom start page implemented , and on this start page you can see a list of orders to open in custom form and modify and save.

When an order is already open in the standard Select window, we would like to also be able to open it (ideally grabbing the currently open order instance) in our custom form update and save, pushing the changes back to the currently open select window for the order.

Below was our attempt at getting the order if its open, otherwise calling the order store:

Code: Select all

IWindowManager windows = WindowManager.Windows.ToList();
foreach (var doc in windows)
{
 	var order = doc.GetProperty("Order") as IOrder;
         if (order?.Guid == orderId)
         	return order;
}

return  OrderStore.OpenOrder(new OrderIdentifier(orderId), OrderEditMode.ReadWrite);   

How ever this through various errors for us occuring on var order = doc.GetProperty("Order") as IOrder;:
1. occasionally get an error telling us to install GdPicture.NET Package.
2. a JIT caught exception saying the enumeration has been modified.

Neither of this errors make any sense based on the code above.

We would like to know how to retrieve an open order (that may or may not be open) from another window without redirecting the user to the order window.
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Retrieving order already open in UI

Post by BobRichards »

We support client packages getting the IOrder from document windows. This is one of the ways to do it by slightly modifying your code.

Code: Select all

Guid orderId = ...  // Target order guid.

// Get list of windows that could possibly hold orders.
IWindowManager winMgr = GetService<IWindowManager>();
List<IWindowFrame> frames = winMgr.Windows
    .Where(t => t.DocumentHandle != Guid.Empty)
    .ToList();

// Search order windows for the target order.
foreach (var frame in frames)
{
    var order = frame.GetProperty("Order") as IOrder;
    if (order?.Guid == orderId)
    {
        return order;
    }
}
On client startup for me, there are 30+ windows in the list of winMgr.Windows and none are actually holding orders since they are ToolWindows. It is possibly, however, that by accessing them with the GetProperty() method, they may be activated and execute code that is invalid in this state and that is generating your strange error messages. The code fragment filters out all these windows before testing the item for the target order guid.
Bob Richards, Senior Software Developer, SoftPro
Post Reply