Add Checklist task based on Requested Task Name

Questions about and code samples for automation process code snippets within Select.
BobRichards
Posts: 906
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Add Checklist task based on Requested Task Name

Post by BobRichards » Tue Feb 13, 2018 3:20 pm

Remember that Automation processing will send the changed Requested Task to you as the Context in this setup. You don't need to get it yourself by enumerating the order collection.

Perhaps the following will give you some ideas about adding checklist items. This snippet must be set up in SPAdmin as "Every time a task is added or updated and task type if Requested then do the following: run code snippet". When the user changes a Requested Task in an order then closes it, the code below executes to create three checklist tasks. If the names already exist, they will not be added again.

Code: Select all

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

# Create a new checklist task.  If an item with the same description 
#   already exists then it will NOT be created again.
def CreateChecklistTask(order, tasks, description, reqTask):
	# If we find it already in checklist collection then items is True.
	items = [t for t in order.ChecklistTasks if t.Description.lower() == description.lower()]
	if items:
		return
		
	# Checklist doesn't exist already - create it.
	ct = IOrder.CreateNew(order, 'ChecklistTask')
	tasks.Add(ct)
	ct.Description = description
	ct.Status = TaskStatusType.Required
	ct.AssignedTo = order.Escrow.PreCloserEscrowAssistant
	ct.DueDate = reqTask.CreatedDate.AddDays(4)


# If Req task starts with magic string then create Checklist tasks
desc = Context.Description
if desc.lower().startswith('abc'):

	# Helper vars.	
	order = Context.Root
	tasks = order.Tasks
	
	# Create three additional checklist tasks.
	CreateChecklistTask(order, tasks, desc + ' - Huey', Context)
	CreateChecklistTask(order, tasks, desc + ' - Dewey', Context)
	CreateChecklistTask(order, tasks, desc + ' - Louie', Context)


Bob Richards, Software Developer, SoftPro

Post Reply