Remove a checklist task from order

Questions about and code samples for automation process code snippets within Select.
Post Reply
kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

Remove a checklist task from order

Post by kkirkfield »

SoftPro Select has it's own collection implementations (E.g. SoftPro.EntityModel.Collections.Set<T>). This is used for Order.ChecklistTasks. As far as I can tell, all the methods to add to and remove from the list have been overridden and hidden. What is the proper way to add and remove checklist tasks to an order?
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Remove a checklist task from order

Post by BobRichards »

We frequently use a general pattern when dealing with collections that inherit from a base class that is also exposed on the order model. Below is an example of removing a Checklist Task.

Code: Select all

// Get the Checklist Task to delete.  We are using the first but could find a specific one.
IList checklists = (IList)order.GetProperty("ChecklistTasks");
IOrderItem checklist = (IOrderItem)(checklists[0]);

// Remove the Checklist Task (or Requested Task) from the list of all tasks.
IList tasks = (IList)order.GetProperty("Tasks");
tasks.Remove(checklist);
	
// Save order changes.
os.ApplyChanges(order);
Checklist Tasks and Requested Tasks inherit from the Task object and are exposed as separate collections to make searching easier. However, you must add or remove from the Tasks list.

By the way, we also do this when creating/removing contacts (such as a Settlement Agent). You create a new "SettlementAgent" object then add it to the Contacts collection (not the SettlementAgent collection).
Bob Richards, Senior Software Developer, SoftPro
Post Reply