Page 1 of 1

Apply Template From Automation

Posted: Thu Jul 20, 2023 11:11 am
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

Re: Apply Template From Automation

Posted: Wed Jul 26, 2023 5:04 pm
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()

Re: Apply Template From Automation

Posted: Fri Aug 04, 2023 7:42 pm
by timothymeyer16
Works perfectly!! Thank you.