×

Scenarios

A Scenario represents a set of tasks and resources and associated schedules. The actuals for a project are one scenario, and saved baselines are the others.

Instance Properties

The properties of a scenario:

The Fixed Start/End and Specific/Relative Dates Properties

(⬇ see below ) The hasFixedEndDate and hasGenericDates properties control the input and display of dates for the scenario.  03  This illustration shows a project with a fixed end:  01 

fixed-end-start

(⬇ see below ) The hasFixedEndDate and hasGenericDates properties control the input and display of dates for the scenario.  03  This illustration shows a project with a fixed start:  01 

fixed-start

Examples of Scenario properties used in scripts:

Scenario Properties


actual.name //--> "Actual" actual.completed //--> 23 // top-level tasks var tasks = actual.rootTask.subtasks // all tasks var allTasks = actual.rootTask.descendents() // new top-level task var newTask = actual.rootTask.addSubtask() // top-level resources var resources = actual.rootResource.members // all resources) var allResources = actual.rootResource.descendents() // new top-level resource var newResource = actual.rootResource.addMember() // all milestones actual.milestones

Total Cost Property

omniplan://localhost/omnijs-run?script=var%20projectCost%20%3D%20actual%2EtotalCost%0Avar%20code%20%3D%20new%20Locale%28%22en%5FUS%22%29%2EcurrencyCode%0Avar%20fmtr%20%3D%20Formatter%2EDecimal%2Ecurrency%28code%29%0Avar%20costString%20%3D%20fmtr%2EstringFromDecimal%28projectCost%29%0Anew%20Alert%28%22Total%20Cost%22%2C%20costString%29%2Eshow%28%29
Show Total Project Cost (USA Dollars)
 

var projectCost = actual.totalCost //--> [object Decimal: 9000] var code = new Locale("en_US").currencyCode //--> "USD" var fmtr = Formatter.Decimal.currency(code) var costString = fmtr.stringFromDecimal(projectCost) //--> "$9,000.00" new Alert("Total Cost", costString).show()

NOTE: Information regarding Locale codes can be found in the Calendar class documentation. Documentation regarding the Decimal Formatter class can be found here.

Instance Functions

Instance functions for the Scenario class.

Assigning Resource to New Task


var rsc = actual.resourceNamed("Margret Jensen") if(rsc){ var task = actual.rootTask.addSubtask() task.addAssignment(rsc) }

NOTE: Both the taskNamed() and the resourceNamed() functions search the entire chain of tasks and resources contained within the container the function is called on, even locating tasks within other tasks. In the example shown below, the taskNamed() function is called on the main project scenario (actual) and so will search the entire scenario.

task-tree

Setting-up a Scenario

Examples of setting up the default scenario (Actual).

Setting-up the main scenario to begin today:

omniplan://localhost/omnijs-run?script=try%7Bvar%20sDate%20%3D%20new%20Date%28%29%0AsDate%20%3D%20new%20Date%28sDate%2EsetHours%280%2C0%2C0%2C0%29%29%0Aactual%2EstartDate%20%3D%20sDate%0Aactual%2EhasFixedEndDate%20%3D%20false%0Aactual%2EhasGenericDates%20%3D%20false%0Adocument%2Eproject%2Etitle%20%3D%20%22New%20Project%22%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Scenario Begins Today
 

var sDate = new Date() sDate = new Date(sDate.setHours(0,0,0,0)) actual.startDate = sDate actual.hasFixedEndDate = false actual.hasGenericDates = false document.project.title = "New Project"

 01  Create the start date object for the project by using the standard JavaScript new class constructor to create a new instance of the Date class, describing the current day and time.

 02  Use the JavaScript setHours(…) instance function to set the time of the created date object to midnight. The result will be a date reference in milliseconds (eg: 1556866800000), so place the setHours(…) command within a new Date constructor to convert the resulting milliseconds number into a standard Date object. Then, store the resulting Date object in the variable: sDate

 03  Set the value of the main scenario’s startDate property to the Date object stored in the variable: sDate

 04  Set the value of the main scenario’s hasFixedEndDate property to false, indicating the project should be calculated from the indicated start date/time.

 05  Set the value of the main scenario’s hasGenericDates property to false, indicating that non-relative date values should be used.

 06  Set the value of the title property of the top-level project class to the desired String value.

Using the DateComponents class of the Calendar class to calculated and set up the main scenario to end in 90 days from today:

omniplan://localhost/omnijs-run?script=var%20cal%20%3D%20Calendar%2Ecurrent%0Avar%20now%20%3D%20new%20Date%28%29%0Avar%20today%20%3D%20cal%2EstartOfDay%28now%29%0Avar%20dc%20%3D%20new%20DateComponents%28%29%0Adc%2Eday%20%3D%2090%0Avar%20targetDate%20%3D%20cal%2EdateByAddingDateComponents%28today%2C%20dc%29%0Aactual%2EendDate%20%3D%20targetDate%0Aactual%2EhasFixedEndDate%20%3D%20true%0Aactual%2EhasGenericDates%20%3D%20false%0Adocument%2Eproject%2Etitle%20%3D%20%2290%2DDay%20Wonder%22
Scenario Ends in 90 Days
 

var cal = Calendar.current var now = new Date() var today = cal.startOfDay(now) var dc = new DateComponents() dc.day = 90 var targetDate = cal.dateByAddingDateComponents(today, dc) actual.endDate = targetDate actual.hasFixedEndDate = true actual.hasGenericDates = false document.project.title = "90-Day Wonder"

 1  Store a reference to the current Calendar.

 2  Store an instance of the current date object.

 3  Use the startOfDay() function to set the time of the stored date object to midnight.

 4  Store a blank instance of the DateComponents class.

 5  Set the value of day property of the new DateComponents instance to 90.

 6  Use the dateByAddingDateComponents() function of the DateComponents class to calculate the date object 90 days from the current date.

 7  Set the value of the main scenario’s endDate property to the Date object stored in the variable: targetDate

 8  Set the value of the main scenario’s hasFixedEndDate property to true, indicating the project should be calculated from the indicated ending date/time.

 9  Set the value of the main scenario’s hasGenericDates property to false, indicating that non-relative date values should be used.

 10  Set the value of the title property of the top-level project class to the desired String value.

Setting-up the main scenario to end on a specific date:

omniplan://localhost/omnijs-run?script=actual%2EhasFixedEndDate%20%3D%20true%0Aactual%2EhasGenericDates%20%3D%20false%20%2F%2F%20specific%0Aactual%2EendDate%20%3D%20new%20Date%28%227%2F4%2F2021%22%29%0Adocument%2Eproject%2Etitle%20%3D%20%224th%20of%20July%20Event%22%0Atask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0Atask%2Etitle%20%3D%20%221st%20Planning%20Session%22%0Atask%2EmanualStartDate%20%3D%20new%20Date%28%222%2F1%2F2021%22%29%0Atask%2EmanualEndDate%20%3D%20new%20Date%28%222%2F2%2F2021%22%29%0Atask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0Atask%2Etitle%20%3D%20%222nd%20Planning%20Session%22%0Atask%2EmanualStartDate%20%3D%20new%20Date%28%223%2F1%2F2021%22%29%0Atask%2EmanualEndDate%20%3D%20new%20Date%28%223%2F2%2F2021%22%29
Project with End Date
 

actual.hasFixedEndDate = true actual.hasGenericDates = false // specific actual.endDate = new Date("7/4/2021") document.project.title = "4th of July Event" task = actual.rootTask.addSubtask() task.title = "1st Planning Session" task.manualStartDate = new Date("2/1/2021") task.manualEndDate = new Date("2/2/2021") task = actual.rootTask.addSubtask() task.title = "2nd Planning Session" task.manualStartDate = new Date("3/1/2021") task.manualEndDate = new Date("3/2/2021")
fixed-end-project fixed-end-project-02