×

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:

Instance Functions

The functions that can be run on an instance of the Assignment class:

Creating an Assignment

To create an instance of the Assignment class use the addAssignment(…) function of the Task class.

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:

omniplan://localhost/omnijs-run?script=var%20rsc%20%3D%20actual%2ErootResource%2EaddMember%28%29%0Arsc%2Etype%20%3D%20ResourceType%2Eequipment%0Arsc%2Ename%20%3D%20%22EXPENSIVE%20BACKHOE%22%0Avar%20costValue%20%3D%20Decimal%2EfromString%28%22275%22%29%0Arsc%2EcostPerHour%20%3D%20costValue%0A%0Avar%20task%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0Atask%2Etitle%20%3D%20%22EXPENSIVE%20TASK%22%0Atask%2EaddAssignment%28rsc%29%0Atask%2Eduration%20%3D%20Duration%2EworkHours%2815%29%0Aconsole%2Elog%28task%2EtotalCost%29
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:

omniplan://localhost/omnijs-run?script=var%20threshold%20%3D%20Decimal%2EfromString%28%222000%22%29%0A%0Avar%20allTasks%20%3D%20actual%2ErootTask%2Edescendents%28%29%0Avar%20taskReferenceArray%20%3D%20new%20Array%28%29%0AallTasks%2EforEach%28task%20%3D%3E%20%7B%0A%09var%20assignmentObjs%20%3D%20task%2Eassignments%0A%09var%20i%3B%0A%09for%20%28i%20%3D%200%3B%20i%20%3C%20assignmentObjs%2Elength%3B%20i%2B%2B%29%20%7B%20%0A%20%20%09%09var%20tCost%20%3D%20assignmentObjs%5Bi%5D%2EtotalCost%0A%20%20%09%09if%28tCost%2Ecompare%28threshold%29%20%3E%3D%200%29%7B%0A%20%20%09%09%09taskReferenceArray%2Epush%28task%29%0A%20%20%09%09%09break%0A%20%20%09%09%7D%0A%09%7D%0A%7D%29%0Aif%28taskReferenceArray%2Elength%20%3E%200%29%7B%0A%09var%20identifiers%20%3D%20taskReferenceArray%2Emap%28task%20%3D%3E%20task%2EuniqueID%29%0A%09var%20IDstr%20%3D%20identifiers%2Ejoin%28%22%2C%22%29%0A%09URL%2EfromString%28%60omniplan%3A%2F%2F%2Ftask%2F%24%7BIDstr%7D%60%29%2Eopen%28%29%0A%7D
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() }