Automate "X" in Pager field if there is a 2nd person under Selling Broker

Questions about and code samples for automation process code snippets within Select.
Post Reply
aottilo
Posts: 7
Joined: Thu Apr 13, 2023 11:00 am

Automate "X" in Pager field if there is a 2nd person under Selling Broker

Post by aottilo »

I am trying to run an automation that if there is a 2nd person under Selling Agent/Broker and either the 1st person or 2nd person Pager field is empty, than populate "X" in the pager field. I am pretty new and trying to do my own code snippet. I am getting this error when the automation runs:
Error: The automation instance failed.
Stack Trace:
at SoftPro.Select.Server.Automation.Runtime.XamlWorkflowInstanceWorker.OnStart(EventArgs args, CancellationToken cancellationToken) in D:\a\1\s\Code\SPNet\Select\SelectServer\Automation\Runtime\XamlWorkflowInstanceWorker.cs:line 176
at SoftPro.Select.Server.Automation.Runtime.WorkflowInstanceWorker.Start(EventArgs args, CancellationToken cancellationToken) in D:\a\1\s\Code\SPNet\Select\SelectServer\Automation\Runtime\WorkflowInstanceWorker.cs:line 81
at SoftPro.Select.Server.Automation.Runtime.WorkflowController.Start(WorkflowInstance instance, EventArgs args) in D:\a\1\s\Code\SPNet\Select\SelectServer\Automation\Runtime\WorkflowController.cs:line 468
***********************************************************************************
Error: name 'Order' is not defined
Stack Trace:
at SoftPro.ClientModel.AsyncResult`1.get_Result() in D:\a\1\s\Code\SPNet\Models\ClientModel\AsyncResult.cs:line 91
at SoftPro.Select.Server.Automation.Builtin.CodedActionActivity.EndExecute(NativeActivityContext context, IAsyncResult result) in D:\a\1\s\Code\SPNet\Select\SelectServer\Automation\Builtin\CodedActionActivity.cs:line 138
at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)


This is what I have. Any suggestions?


Image

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

order = Order()

selling_agent_brokers = order.SellingAgentBrokers

# Initialize the selling_agent_brokers variable if not already initialized
if selling_agent_brokers is None:
selling_agent_brokers = []

# Perform the condition check and update the Pager values
if (
selling_agent_brokers and
selling_agent_brokers.Count >= 1 and
selling_agent_brokers[0].People and
selling_agent_brokers[0].People.Count >= 2 and
selling_agent_brokers[0].People[1].FirstName and
(
String.IsNullOrEmpty(selling_agent_brokers[0].People[0].Pager) or
String.IsNullOrEmpty(selling_agent_brokers[0].People[1].Pager)
)
):
# Set the Pager value to "X" for the relevant persons
if String.IsNullOrEmpty(selling_agent_brokers[0].People[0].Pager):
selling_agent_brokers[0].People[0].Pager = "X"
if String.IsNullOrEmpty(selling_agent_brokers[0].People[1].Pager):
selling_agent_brokers[0].People[1].Pager = "X"
BobRichards
Posts: 1382
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Automate "X" in Pager field if there is a 2nd person under Selling Broker

Post by BobRichards »

I assume you have set up an Automation Snippet to run "Everytime an order is saved". In that case, the order object is held in the variable "Context".

Code: Select all

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

Context.Project = str(DateTime.Now)
Yields:
2023-05-31_17-08-15.jpg
2023-05-31_17-08-15.jpg (11.1 KiB) Viewed 5606 times
Bob Richards, Senior Software Developer, SoftPro
Post Reply