Apply Template From Automation

Questions about and code samples for automation process code snippets within Select.
Post Reply
timothymeyer16
Posts: 37
Joined: Mon Jun 14, 2021 9:47 am

Apply Template From Automation

Post by timothymeyer16 »

SoftPro Developer Team,

Currently, I'm having some issues with applying a template from a python automation, but not from C#.

Working C# Code

Code: Select all

// Apply Template
                IOrderStore os = SelectServer.GetService<IOrderStore>();
                IOrderInfo info = os.Orders.Where(t => t.Number == "Template").FirstOrDefault();
                IOrder template = os.OpenOrder(info, OrderEditMode.ReadOnly);
                o.ApplyTemplate(template);
Failing Python Code

Code: Select all

def AddTemplates():	
	os = Context.Root.GetService(IOrderStore)	
	info = os.Orders.Where(lambda s: s.Number == "Default").FirstOrDefault() // Error Here
	template = os.OpenOrder(info, OrderEditMode.ReadOnly)
	Context.ApplyTemplate(template)
AddTemplates()
The error I receive in Automation is "OrderStore object has no attribute Orders", when trying to set the info variable, which seems to contradict the documentation.

Image

Please let me know if you have any direction here. The main objective is to add logic to an automation and apply different templates based on conditions without needing to create separate automations.

Thank you,

Tim
Attachments
2.PNG
2.PNG (26.81 KiB) Viewed 5004 times
PaulMcCullough
Posts: 23
Joined: Wed Jul 12, 2023 11:29 am

Re: Apply Template From Automation

Post by PaulMcCullough »

The syntax to access properties and methods on Select objects is a bit more complicated in python. Below is a modification of your code that we were able to successfully run.

To get the value of a property using an interface, use <interface name>.<property>.GetValue(<object instance>). You can see an example on the second line of the function.

An example of calling a method is on the last line of the function. Use <interface name>.<method name>(<object instance>, <other parameters>)

Also note the 4 lines of code that import the LINQ libraries.

I hope this helps!

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *

# Include LINQ
import clr
import System
clr.AddReference('System.Core')
clr.ImportExtensions(System.Linq)

def AddTemplates():	
	os = Context.Root.GetService(IOrderStore)
	info = IOrderStore.Orders.GetValue(os).Where(lambda s: s.Number == "Default").FirstOrDefault()
	template = IOrderStore.OpenOrder(os, info, OrderEditMode.ReadOnly)
	IOrder.ApplyTemplate(Context, template)
AddTemplates()
timothymeyer16
Posts: 37
Joined: Mon Jun 14, 2021 9:47 am

Re: Apply Template From Automation

Post by timothymeyer16 »

Works perfectly!! Thank you.
Post Reply