Tasks

A Task is an element of a Scenario, and is anything that needs to get done in order for the project to move toward completion. Each task has attributes such as start and end dates, a completion percentage, and resource assignments.

Instance Properties

As with most scriptable objects, instances of the Task class have properties that define their abilities and usage.

NOTE: r/o indicates a property whose value can only be read, not changed by the script.

Instance Functions

The following functions can be performed on instances of the Task class.

Task Types (TaskType class)

Here are the various properties of the TaskType class that are used as values for the type property of the Task class:

task = actual.rootTask.addSubtask() task.type = TaskType.group

Reference Existing Task

To generate a reference to an existing task, use the taskNamed() function of the Scenario class, which searches the entire hierarchy of tasks, to return the first matching task. In the following example, a reference to a task is generated and if the task does not exist, one will be created and the reference to the new task stored.

taskName = "Build Porch" task = actual.taskNamed(taskName) if(!task){ task = actual.rootTask.addSubtask() task.name = taskName }

Removing Tasks

Using the remove() instance function of the Task class, scripts can delete tasks from a project or task container.

actual.rootTask.descendents().forEach((task)=>{task.remove()})
omniplan://localhost/omnijs-run?script=try%7Bactual%2ErootTask%2Edescendents%28%29%2EforEach%28%28task%29%3D%3E%7Btask%2Eremove%28%29%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

Creating Tasks

Tasks are created by calling the addSubtask() method on an task instance. The result will be a reference to the newly created task, which will be added to the specified task as a subtask. To create a task at the top-level of the scenario, apply the method to the rootTask object.

// CREATE TOP-LEVEL TASKS createdTasks = new Array() taskTitles = ["rake leaves","mow lawn","clean gutters","trim hedges"] taskTitles.forEach((taskTitle)=>{ task = actual.rootTask.addSubtask() task.title = taskTitle createdTasks.push(task) })
omniplan://localhost/omnijs-run?script=try%7BcreatedTasks%20%3D%20new%20Array%28%29%0AtaskTitles%20%3D%20%5B%22rake%20leaves%22%2C%22mow%20lawn%22%2C%22clean%20gutters%22%2C%22trim%20hedges%22%5D%0AtaskTitles%2EforEach%28%28taskTitle%29%3D%3E%7B%0A%09task%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0A%09task%2Etitle%20%3D%20taskTitle%0A%09createdTasks%2Epush%28task%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 1  Instantiate a new variable that will hold an array of references to the created tasks.

 2  An array of titles for the new tasks.

 3-7  Use the JavaScript forEach() function to iterate the list of new task titles, creating a new task for each title.

 6  Use the JavaScript push() function to append a reference to the new task to the array of created task references.

By default in OmniPlan, multiple tasks may share the same title. In the following script examples, the taskNamed() function of the Scenario class is used to check for an existing task with the targeted name, in order to ensure that no duplicate tasks are created and that all tasks have a unique title.

Here are script examples of creating tasks using a list of potential task titles.

// CREATE UNIQUELY-NAMED TOP-LEVEL TASKS createdTasks = new Array() taskTitles = ["rake leaves","mow lawn","clean gutters","trim hedges"] taskTitles.forEach((taskTitle)=>{ if(!actual.taskNamed(taskTitle)){ task = actual.rootTask.addSubtask() task.title = taskTitle createdTasks.push(task) } }) console.log(createdTasks)
omniplan://localhost/omnijs-run?script=try%7BcreatedTasks%20%3D%20new%20Array%28%29%0AtaskTitles%20%3D%20%5B%22rake%20leaves%22%2C%22mow%20lawn%22%2C%22clean%20gutters%22%2C%22trim%20hedges%22%5D%0AtaskTitles%2EforEach%28%28taskTitle%29%3D%3E%7B%0A%09if%28%21actual%2EtaskNamed%28taskTitle%29%29%7B%0A%09%09task%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0A%09%09task%2Etitle%20%3D%20taskTitle%0A%09%09createdTasks%2Epush%28task%29%0A%09%7D%0A%7D%29%0Aconsole%2Elog%28createdTasks%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 1  Instantiate a new variable that will hold an array of references to the created tasks.

 2  An array of titles for the new tasks.

 3  Use the descendents() method on the rootTask to retrieve an array of references to every task in the entire scenario hierarchy. Then use the JavaScript map() function to iterate the list of references, returning the titles of each task, and store the resulting array in the variable: allTaskTitles

 4-11  Use the JavaScript forEach() function to iterate the list of new task titles, creating a new task for each title.

 5-10  A JavaScript conditional statement to check to see if the array of every task title does not contain the title to be used for the new task.

 6  Create a new top-level task by using the addSubtask() method on the rootTask of the scenario, and store the resulting reference to the new task in a variable.

 7  Title the newly created task using the passed-in title from list of new task titles.

 8  Use the JavaScript push() function to append the title of the new task to the array of all task titles.

 9  Use the JavaScript push() function to append a reference to the new task to the array of created task references.

A Task instance may contain other tasks, in which case it is referred to as a “Task Group.”

A Task Group is created by using the addSubtask() function on a specified task, for each of the desired subtasks to be added.

In the following script example, a top-level task is created, and multiple subtasks are added to the created top-level task. As with the previous script example, a list of all task names is generated to be used to ensure that the title of the top-level task is unique.

// CREATE UNIQUELY-NAMED TOP-LEVEL TASK GROUP groupTitle = "Home Exterior Maintenance" allTaskTitles = actual.rootTask.descendents().map((task)=>{return task.title}) if(!allTaskTitles.includes(groupTitle)){ jobTitles = ["rake leaves","mow lawn","clean gutters","trim hedges"] var groupTask = actual.rootTask.addSubtask() groupTask.title = groupTitle groupTask.type = TaskType.group jobTitles.forEach((jobTitle)=>{ groupTask.addSubtask().title = jobTitle }) }
omniplan://localhost/omnijs-run?script=try%7BgroupTitle%20%3D%20%22Home%20Exterior%20Maintenance%22%0AallTaskTitles%20%3D%20actual%2ErootTask%2Edescendents%28%29%2Emap%28%28task%29%3D%3E%7Breturn%20task%2Etitle%7D%29%0Aif%28%21allTaskTitles%2Eincludes%28groupTitle%29%29%7B%0A%09jobTitles%20%3D%20%5B%22rake%20leaves%22%2C%22mow%20lawn%22%2C%22clean%20gutters%22%2C%22trim%20hedges%22%5D%0A%09var%20groupTask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0A%09groupTask%2Etitle%20%3D%20groupTitle%0A%09groupTask%2Etype%20%3D%20TaskType%2Egroup%0A%09jobTitles%2EforEach%28%28jobTitle%29%3D%3E%7B%0A%09%09groupTask%2EaddSubtask%28%29%2Etitle%20%3D%20jobTitle%0A%09%7D%29%0A%7D%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 1  Store the title, to be used for the group task, in a variable

 2  Generate a list of all task titles by using the descendents() instance function with the rootTask object to return an array of references to every task, and then use the JavaScript map() function to extract the title of each task.

 3-11  A JavaScript conditional statement to confirm that the title for the group task has not already been used for another task.

 4  A list of titles for the subtasks of the created group task.

 5  Use the addSubtask() instance function on the rootTask object to create a new top-level task.

 6  Title the newly created task.

 7  Set the task’s type to be a group task.

 8  Use the JavaScript forEach() function to iterate the list of subtask names, creating a new task for each within the group task.

Milestones

Milestones are the anchor points in your project that mark important shifts in focus or unlocking a new phase of the project. Clarifying these will help break a dauntingly large project down into more manageable sections, and help dictate the tasks leading up to and following the milestone.

A Milestone is a Task with no duration. Milestones are used to mark specific points within the project. In the following script example, a milestone marking the project end is created 90 days from the current date.

var eDate = new Date(new Date().setHours(0,0,0,0)) eDate = new Date(eDate.setDate(eDate.getDate() + 90)) task = actual.rootTask.addSubtask() task.title = "Project End" task.type = TaskType.milestone task.lockedStartDate = eDate
omniplan://localhost/omnijs-run?script=try%7Bvar%20eDate%20%3D%20new%20Date%28new%20Date%28%29%2EsetHours%280%2C0%2C0%2C0%29%29%0AeDate%20%3D%20new%20Date%28eDate%2EsetDate%28eDate%2EgetDate%28%29%20%2B%2090%29%29%0Atask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0Atask%2Etitle%20%3D%20%22Project%20End%22%0Atask%2Etype%20%3D%20TaskType%2Emilestone%0Atask%2ElockedStartDate%20%3D%20eDate%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER