Add Checklist task based on Requested Task Name
Add Checklist task based on Requested Task Name
I am trying to loop through the requested tasks until I find a task with "Exam - UP" in the name. Then I am reading the last two characters from that task which will be the task number ie "Exam - UP01" result will return "01". Now I create the new checklist name "'Exam - UP' + PLTaskName + ': Searched'" Then create the checklist task. I get the following error:
"Collection was modified; enumeration operation may not execute."
Help Please!
Thanks
Dan
from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Security import *
###################################################################
# Snippet type: Action
# Description: Create Exam update Task
####################################################################
for task in Context.RequestedTasks:
PLTaskName = task.Description
if PLTaskName.lower().startswith('exam - up'):
#continue
PLTaskName = task.Description[-2:]
PLCTaskName = 'Exam - UP' + PLTaskName + ': Searched'
#raise ValueError(PLCTaskName)
newtask = IOrder.CreateNew(Context, 'ChecklistTask')
newtask.Description = PLCTaskName
newtask.Status = TaskStatusType.Required
newtask.AssignedTo = Context.Escrow.PreCloserEscrowAssistant
newtask.DueDate = newtask.CreatedDate.AddDays(4)
#newtask.Contact = payofflender
Context.Tasks.Add(newtask)
"Collection was modified; enumeration operation may not execute."
Help Please!
Thanks
Dan
from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Security import *
###################################################################
# Snippet type: Action
# Description: Create Exam update Task
####################################################################
for task in Context.RequestedTasks:
PLTaskName = task.Description
if PLTaskName.lower().startswith('exam - up'):
#continue
PLTaskName = task.Description[-2:]
PLCTaskName = 'Exam - UP' + PLTaskName + ': Searched'
#raise ValueError(PLCTaskName)
newtask = IOrder.CreateNew(Context, 'ChecklistTask')
newtask.Description = PLCTaskName
newtask.Status = TaskStatusType.Required
newtask.AssignedTo = Context.Escrow.PreCloserEscrowAssistant
newtask.DueDate = newtask.CreatedDate.AddDays(4)
#newtask.Contact = payofflender
Context.Tasks.Add(newtask)
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Add Checklist task based on Requested Task Name
I can't guarantee this is the answer since you didn't enter your code in the code display formatter (button above labelled "</>") and all white space disappeared. However, this is the classic error of attempting to modify a collection that you are looping on.
Your "for" loop gets its tasks from the RequestedTasks collection - and Context.Tasks is the data source for this collection. You are not allowed to modify the collection members (add or remove) while you are looping on them.
Code: Select all
for task in Context.RequestedTasks:
...
Context.Tasks.Add(newtask)
Bob Richards, Senior Software Developer, SoftPro
Re: Add Checklist task based on Requested Task Name
So I am looping through the requested tasks to set a name variable that will be used to create a Checklist Task. How would I do that?
Here is the formatted code
Here is the formatted code
Code: Select all
rom System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Security import *
###################################################################
# Snippet type: Action
# Description: Create Exam update Task
####################################################################
for task in Context.RequestedTasks:
PLTaskName = task.Description
if PLTaskName.lower().startswith('exam - up'):
#continue
PLTaskName = task.Description[-2:]
PLCTaskName = 'Exam - UP' + PLTaskName + ': Searched' # Creates the task name to be created
#raise ValueError(PLCTaskName)
newtask = IOrder.CreateNew(Context.ChecklistTasks, 'ChecklistTask')
newtask.Description = PLCTaskName
newtask.Status = TaskStatusType.Required
newtask.AssignedTo = Context.Escrow.PreCloserEscrowAssistant
newtask.DueDate = newtask.CreatedDate.AddDays(4)
#newtask.Contact = payofflender
Context.Tasks.Add(newtask)
Re: Add Checklist task based on Requested Task Name
Can we use and return a function within a code snipped to separate the loop from the create task code? I am not sure what that syntax would look like in an automation snippet?
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Add Checklist task based on Requested Task Name
Among the many ways this can be done, you could store the list of items that you create then add the items after the loop. (Code below is untested but should get the point across.)
Code: Select all
holdingList = []
for task in Context.RequestedTasks:
...
// Create new item and add it to holding list.
newtask = IOrder.CreateNew(Context.ChecklistTasks, 'ChecklistTask')
...
holdingList.append(newTask)
// All RequestedTasks processed. Now add any new tasks that were created.
foreach task in holdingList:
Context.Tasks.Add(newtask)
Bob Richards, Senior Software Developer, SoftPro
Re: Add Checklist task based on Requested Task Name
Code: Select all
holdingList = []
for task in Context.RequestedTasks:
PLTaskName = task.Description
if PLTaskName.lower().startswith('exam - up'):
#continue
PLTaskName = task.Description[-2:]
PLCTaskName = 'Exam - UP' + PLTaskName + ': Searched'
#raise ValueError(getUpdateNo())
newtask = IOrder.CreateNew(Context.ChecklistTasks, 'ChecklistTask') # Create new item and add it to holding list
newtask.Description = PLCTaskName
newtask.Status = TaskStatusType.Required
newtask.AssignedTo = Context.Escrow.PreCloserEscrowAssistant
newtask.DueDate = newtask.CreatedDate.AddDays(4)
#newtask.Contact = payofflender
holdingList.append(newTask)
# All RequestedTasks processed. Now add any new tasks that were created.
foreach task in holdingList:
Context.Tasks.Add(newtask)
Unexpected token ‘task’
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Add Checklist task based on Requested Task Name
Oops. Try "for item in holdingList:" instead of "foreach". This page is handy for Python list questions: http://effbot.org/zone/python-list.htm
Bob Richards, Senior Software Developer, SoftPro
Re: Add Checklist task based on Requested Task Name
Thanks Bob, I had already changed and tried "for" rather than "foreach", after making that change and running from the code below, I get the following error:
expected IOrder, got Set[ChecklistTask]
My Code:
expected IOrder, got Set[ChecklistTask]
My Code:
Code: Select all
from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Security import *
###################################################################
# Snippet type: Action
# Description: Create Exam update Task
####################################################################
holdingList = []
for task in Context.RequestedTasks:
PLTaskName = task.Description
if PLTaskName.lower().startswith('exam - up'):
#continue
PLTaskName = task.Description[-2:]
PLCTaskName = 'Exam - UP' + PLTaskName + ': Searched'
#raise ValueError(getUpdateNo())
newtask = IOrder.CreateNew(Context.ChecklistTasks, 'ChecklistTask') # Create new item and add it to holding list
newtask.Description = PLCTaskName
newtask.Status = TaskStatusType.Required
newtask.AssignedTo = Context.Escrow.PreCloserEscrowAssistant
newtask.DueDate = newtask.CreatedDate.AddDays(4)
#newtask.Contact = payofflender
holdingList.append(newTask)
# All RequestedTasks processed. Now add any new tasks that were created.
for task in holdingList:
Context.Tasks.Add(newtask)
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Add Checklist task based on Requested Task Name
You should be passing the Order to the object creator:
Code: Select all
...
newtask = IOrder.CreateNew(Context.Root, 'ChecklistTask')
...
Bob Richards, Senior Software Developer, SoftPro
Re: Add Checklist task based on Requested Task Name
Still getting error: This time "An Item with the same key has already been added" code below
Code: Select all
from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Security import *
###################################################################
# Snippet type: Action
# Description: Create Exam update Task
####################################################################
holdingList = []
for task in Context.RequestedTasks:
UPDTaskName = task.Description
if UPDTaskName.lower().startswith('exam - up'):
#continue
UPDTaskName = task.Description[-2:]
UPDTaskName = 'Exam - UP' + UPDTaskName + ': Searched'
#raise ValueError(getUpdateNo())
# Create new item and add it to holding list
#newtask = IOrder.CreateNew(Context.ChecklistTasks, 'ChecklistTask') #expected IOrder, got Set[ChecklistTask]
#newtask = IOrder.CreateNew(Context.Root.ChecklistTasks, 'ChecklistTask') #expected IOrder, got Set[ChecklistTask]
newtask = IOrder.CreateNew(Context.Root, 'ChecklistTask')
newtask.Description = UPDTaskName
newtask.Status = TaskStatusType.Required
newtask.AssignedTo = Context.Escrow.PreCloserEscrowAssistant
newtask.DueDate = newtask.CreatedDate.AddDays(4)
#holdingList.append(newTask) #newTask is not defined
holdingList.append(newtask)
# All RequestedTasks processed. Now add any new tasks that were created.
for task in holdingList:
Context.Tasks.Add(newtask)