TemplateHistory collection

Discussions related to custom development with Select.
Post Reply
sollila_LT
Posts: 3
Joined: Thu Oct 07, 2021 4:19 pm

TemplateHistory collection

Post by sollila_LT »

We are looking to capture template overlays during the OrderSaved event in a server package. I see a previous response to a similar question, https://devforum.softprocorp.com/viewto ... tory#p4486, but am not seeing the TemplateHistory collection when opening an order from the OrderStore. Is this collection still available, and would it also be available on the Order object passed to the event handler? If so, could we see some sample code? This seems like it would be more performant than pulling and searching OrderHistory.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: TemplateHistory collection

Post by BobRichards »

I'm not entirely understanding what you are asking for but perhaps this will help.

There is no separate TemplateHistory. A template is an order. It differs only because we treat it differently - meaning we use them to provide initial values for other orders. The OrderHistory is available for a template by using the same process as the code you referenced. The API has changed somewhat over the intervening 5 years so below is the preferred code fragment.

Code: Select all

string templateNumber = "CDFTemplate"; // Example name of a template.

// Open order (read-only in this example).
IOrderStore os = ss.GetService<IOrderStore>();
IOrderInfo templateInfo = os.Orders.Where(t => t.Number == templateNumber).FirstOrDefault();
IOrder template = os.OpenOrder(orderInfo, OrderEditMode.ReadOnly);

// Get all order history from latest template.
IOrderHistory[] hx = os.GetOrderHistory(new OrderIdentifier(iOrder.Guid, -1))
Bob Richards, Senior Software Developer, SoftPro
Post Reply