DefaultTemplate in the API

Discussions related to custom development with Select.
Post Reply
muhsmann
Posts: 54
Joined: Thu Jan 15, 2009 5:41 pm

DefaultTemplate in the API

Post by muhsmann »

Is there a way to dynamically set the Template when creating a new Order via the API? I see the field DefaultTemplateName (readonly) in the OrderTracking class - but I'm not sure how it's used in when creating the Order. Would I have to use different API login credentials to change the template?
Phil Barton
Posts: 54
Joined: Wed Sep 24, 2008 2:37 pm
Location: Raleigh, NC
Contact:

Re: DefaultTemplate in the API

Post by Phil Barton »

Yes, there is a way to specify the template(s) to be used during order creation. Within the OrderCreationSpec class, there is a property named Templates that is a List<string> (or List(Of String) in Visual Basic). You can use the Add(...) method to add the name of the template you wish to use. For example:

Code: Select all

			
			SelectServer server = new SelectServer(null, new Uri(<your URI>), new NetworkCredential(<username>, <password>, SoftPro.Select.Client.Constants.SelectDomain));
			SoftPro.OrderTracking.Client.OrderTracking ot = server.GetService<SoftPro.OrderTracking.Client.OrderTracking>();

			OrderCreationSpec spec = new OrderCreationSpec();

			spec.Templates.Add(@"MyTemplate");

			using ( IOrder order = ot.CreateOrder(spec) )
			{
				try
				{
					// Process the order

					ValidationMessage[] messages;

					if ( !ot.SaveOrder(order, out messages) )
					{
						// Handle save failure
					}
				}
				finally
				{
					ot.CloseOrder(order);
				}
			}
Additionally, it should be noted that the default template for a profile is not added automatically to the OrderCreationSpec. It, too, must be explicitly added. On the OrderTracking class, there is a property named DefaultTemplateName. This will return a string containing the default template name for the current profile. Using the above example, the code could be modified as such:

Code: Select all

			SelectServer server = new SelectServer(null, new Uri(<your URI>), new NetworkCredential(<username>, <password>, SoftPro.Select.Client.Constants.SelectDomain));
			SoftPro.OrderTracking.Client.OrderTracking ot = server.GetService<SoftPro.OrderTracking.Client.OrderTracking>();

			OrderCreationSpec spec = new OrderCreationSpec();

			spec.Templates.Add(ot.DefaultTemplateName);
			.
			.
			.
Phil Barton
Software Architect
SoftPro
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

Re: DefaultTemplate in the API

Post by danvanf »

Phil Barton wrote: spec.Templates.Add(@"MyTemplate");
Phil, This might be a newbie question, feel free to point me toward education, but what does the "@" sign do? I have an app that is attaching a template without the @, and I'm wondering if I should be using it. (Whatever IT is <smile>)

FYI My app is running in a stand-alone mode.

Thanks,

Dan Van Fleet
danvanfleet@SoftProDeveloper.com
I blog at http://DanVanFleet.com on SoftPro and other things
jbright

Re: DefaultTemplate in the API

Post by jbright »

danvanf wrote:what does the "@" sign do?
The @ sign is explained in the link below, about halfway down.

http://msdn.microsoft.com/en-us/library ... S.71).aspx
Post Reply