Determine if order is new or existing when being saved

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
daniorg
Posts: 11
Joined: Thu Dec 02, 2010 11:14 am

Determine if order is new or existing when being saved

Post by daniorg »

I have tapped into the save order handler....

Code: Select all

OrderHelper oh = GetService<OrderHelper>();
oh.RegisterOrderSavedHandler(saved_handler);

private void saved_handler(object sender, EventArgs e)
{
    IOrder order = sender as IOrder;
    // check is order is new or existing

}
and now I am wondering if there is a way to determine if the order is a "new" order, or an existing order.....Is this possible?
Mark McKenna

Re: Determine if order is new or existing when being saved

Post by Mark McKenna »

There is a SaveCount property exposed by the IOrder interface which starts at 0. You may be able to use that if your definition of new vs. existing is whether or not an order has yet been saved at least once. The value of SaveCount increments each time the order is saved - for any reason - including those triggered forcibly by the application.
daniorg
Posts: 11
Joined: Thu Dec 02, 2010 11:14 am

Re: Determine if order is new or existing when being saved

Post by daniorg »

That should accomplish what I am looking for, Ill assume that since it starts at 0, the actual value will be 1 when I get access to it as this happens after the order is saved correct?

However, correct me if I am wrong, but auto-saving does NOT fire the Order Saved Event Handler, right?
Mark McKenna

Re: Determine if order is new or existing when being saved

Post by Mark McKenna »

The save occurs before the event handler is invoked so yes, you would see a value of 1 if it was the first time a particular order was saved. As for your other question, the event handler is always invoked when a save occurs while the order is open in Select, even for auto-save and force-save (e.g. when a document job is kicked off).
daniorg
Posts: 11
Joined: Thu Dec 02, 2010 11:14 am

Re: Determine if order is new or existing when being saved

Post by daniorg »

I am running version 2.4 and if I have "Auto Save order at creation" checked, the saved handler isnt invoked.

Is this an exception to the rule or do i have some bad code.
Mark McKenna

Re: Determine if order is new or existing when being saved

Post by Mark McKenna »

No, that's right. When that option is turned on, the order is technically saved before it is opened in Select, so the handler is not invoked (the invocation occurs by way of the editor window itself). If the other option (auto-save every n minutes) is turned on, that will invoke the handler since the order is open in Select. Hope that helps.
Post Reply