DefaultTemplate in the API
DefaultTemplate in the API
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?
-
- Posts: 54
- Joined: Wed Sep 24, 2008 2:37 pm
- Location: Raleigh, NC
- Contact:
Re: DefaultTemplate in the API
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:
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(@"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);
}
}
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
Software Architect
SoftPro
Re: DefaultTemplate in the API
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>)Phil Barton wrote: spec.Templates.Add(@"MyTemplate");
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
Re: DefaultTemplate in the API
The @ sign is explained in the link below, about halfway down.danvanf wrote:what does the "@" sign do?
http://msdn.microsoft.com/en-us/library ... S.71).aspx