Assignments
OmniPlan projects contain tasks that are accomplished through the use of resources that are both humans and machinery. The relationship between tasks and resources are defined through assignments between a resource and a task.
The value of the properties of an instance of the Assignment class determine the nature of the assignment relationship.
Instance Properties
Here are the properties of an instance of the Assignment class:
isLocal (Boolean r/o) • Whether this assignment is part of this project or not. A non-local assignment comes from sharing resource loads from a server project repository.
resource (Resource r/o) • The Resource of this assignment.
specificAssignments (Array of Assignment r/o) • When the assigned resource is to a resource group, the specific resources within that group who are actually assigned to do the work.
task (Task r/o) • The Task of this assignment.
totalCost (Number r/o) • Total cost of this assignment.
totalDuration (Number r/o) • Total duration of this assignment.
totalEffort (Number r/o) • Total effort performed during this assignment.
unitsAssigned (Number) • Resource units assigned to this task.
Instance Functions
The functions that can be run on an instance of the Assignment class:
remove() • Call to delete this assignment, removing it from it’s task and resource.
Creating an Assignment
To create an instance of the Assignment class use the addAssignment(…) function of the Task class.
addAssignment(to:Resource) → (Assignment) • Create a new assignment to the given resource.
To create an object reference for a specific resource, use the resourceNamed(…) method of the Scenario class, as demonstrated in the following script example:
New Assigned Task
var rsc = actual.resourceNamed("Margret Jensen")
if(rsc){
var task = actual.rootTask.addSubtask()
task.title = "NEW ASSIGNED TASK"
task.addAssignment(rsc)
}
To assign an existing resource to an existing task:
Assign Existing Resource to Existing Task
var rsc = actual.resourceNamed("Margret Jensen")
var task = actual.taskNamed("Merge Data")
if (rsc && task){
task.addAssignment(rsc)
}
Locating Tasks by Assignments
The following pair of scripts demonstrate how to identify tasks with assignments whose cost is over specific threshold:
Select Tasks with Expensive Assignments (setup)
var rsc = actual.rootResource.addMember()
rsc.type = ResourceType.equipment
rsc.name = "EXPENSIVE BACKHOE"
var costValue = Decimal.fromString("275")
rsc.costPerHour = costValue
var task = actual.rootTask.addSubtask()
task.title = "EXPENSIVE TASK"
task.addAssignment(rsc)
task.duration = Duration.workHours(15)
console.log(task.totalCost)
A script for selecting tasks that have assignments whose individual cost is greater than or equal to a threshold:
Select Tasks with Expensive Assignments
var threshold = Decimal.fromString("2000")
var allTasks = actual.rootTask.descendents()
var taskReferenceArray = new Array()
allTasks.forEach(task => {
var assignmentObjs = task.assignments
var i;
for (i = 0; i < assignmentObjs.length; i++){
var tCost = assignmentObjs[i].totalCost
if(tCost.compare(threshold) >= 0){
taskReferenceArray.push(task)
break
}
}
})
if(taskReferenceArray.length > 0){
var identifiers = taskReferenceArray.map(task => task.uniqueID)
var IDstr = identifiers.join(",")
URL.fromString(`omniplan:///task/${IDstr}`).open()
}