Open Order Event

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
Pulte2013
Posts: 2
Joined: Wed Jul 09, 2014 1:45 pm

Open Order Event

Post by Pulte2013 »

Tasked to display a custom notification form when a user displays or opens an order in SoftPro. I’m not able to find an event for Order Open. Anyone know of an event I can use that will fire when an order is opened or displayed in SoftPro?
Thanks
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Open Order Event

Post by BobRichards »

One way is to subscribe to the DocumentOpened event in IRunningDocumentsManager2 in a shell package on the workstation.

Set the autoLoad parameter to true to force the package OnInitialize() method to run at startup.

Code: Select all

[RegisterPackage("My Company", "My Product", "1.0", "", true)]
Subscribe to the IShell.Load event to give all shell packages an opportunity to be initialized before we get any other services. Package loading is indeterminant so you must do this before attempting to get non-IShell services.

Code: Select all

protected override void OnInitialize()
{
  IShell shell = GetService<IShell>();
  shell.Load += new EventHandler(shell_Load);
}
Now that all services are available, subscribe to the DocumentOpened event.

Code: Select all

void shell_Load(object sender, EventArgs e)
{
  // Unhook from the Shell.Load event.
  IShell shell = GetService<IShell>();
  shell.Load -= shell_Load;

  // Hook into client-side Document Open event.
  IRunningDocumentsManager2 docMgr2 = GetService<IRunningDocumentsManager2>();
  docMgr2.DocumentOpened += new EventHandler<DocumentEventArgs>(docMgr2_DocumentOpened);
}
When the user opens a document, the following code will run.

Code: Select all

void docMgr2_DocumentOpened(object sender, DocumentEventArgs e)
{
  // Your code here.
}
Bob Richards, Senior Software Developer, SoftPro
Pulte2013
Posts: 2
Joined: Wed Jul 09, 2014 1:45 pm

Re: Open Order Event

Post by Pulte2013 »

Hi Bob,
Thanks for getting back to me. I am looking for IRunningDocumentsManager2 and can't find that component. I do have IRunningDocumentsManager but it does not have the DocumentOpened event. Any suggestions?
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Open Order Event

Post by BobRichards »

What version are you using?
Bob Richards, Senior Software Developer, SoftPro
chris.brady
Posts: 105
Joined: Wed Oct 17, 2012 4:20 pm

Re: Open Order Event

Post by chris.brady »

Is there a cleaner way to monitor for an order being opened in Cameron? The original poster (he used to work for us) ended up using ActiveWindowChanged in Boylan based on John Morris' recommendation, but we're hoping there's an easier, more direct way in Cameron.
chris.brady
Posts: 105
Joined: Wed Oct 17, 2012 4:20 pm

Re: Open Order Event

Post by chris.brady »

I've attempted to use the DocumentOpened event as this seems to be the approach that was intended for Cameron for determining when an order has been opened. That much seems to be indicated in another forum post when I searched on DocumentOpened.

However, is there any way to get the order that was opened at that point? When running the usual code for getting an active order:

Code: Select all

// Get document from active window if there is one.
IWindowManager wm = GetService<IWindowManager>();
IWindowFrame activeDocument = wm.ActiveDocument;
if (activeDocument != null)
{
    // Now verify active window is an order.
    IOrder activeOrder = activeDocument.GetProperty("Order") as IOrder;
    if (activeOrder != null)
    {
        // Got the active order.
        ...
    }
}
activeOrder always comes back null when called from the DocumentOpened event.

If the order isn't available at this point, is there no other event besides IWindowManager.ActiveWindowChanged that will be useful? That event fires more often than we like, and we're jumping through hoops to make sure the code we've added to that handler only gets called once per order.
chris.brady
Posts: 105
Joined: Wed Oct 17, 2012 4:20 pm

Re: Open Order Event

Post by chris.brady »

We ended up settling with event ActiveDocumentChanged, and it works for the most part, but we've noticed periodic oddities within our code that executes in this event, including "attempt to access disposed object" and the like when accessing the Order object.

Part of the code that fires during this event handler presents the user with a windows form, and adds attachments to the order. It also updates a custom field or two.

Given what we're doing here, is this the appropriate event we should be handling, or is there a better one where we're guaranteed the order is fully open and available for manipulation?
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Open Order Event

Post by John Morris »

Please provide a full call stack of the exceptions you get.
John Morris
Sr. Software Architect
SoftPro
Post Reply