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:

Examples of Scenario properties used in scripts:

Instance Functions

Instance functions for the Scenario class.

rsc = actual.resourceNamed("Margret Jensen") if(rsc){ 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:

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"
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

 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.

Setting-up the main scenario to end in 90 days from today:

var sDate = new Date() sDate = new Date(sDate.setHours(0,0,0,0)) var eDate = new Date(sDate) eDate = new Date(eDate.setDate(eDate.getDate() + 90)) actual.endDate = eDate actual.hasFixedEndDate = true actual.hasGenericDates = false document.project.title = "90-Day Wonder"
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%0Avar%20eDate%20%3D%20new%20Date%28sDate%29%0AeDate%20%3D%20new%20Date%28eDate%2EsetDate%28eDate%2EgetDate%28%29%20%2B%2090%29%29%0Aactual%2EendDate%20%3D%20eDate%0Aactual%2EhasFixedEndDate%20%3D%20true%0Aactual%2EhasGenericDates%20%3D%20false%0Adocument%2Eproject%2Etitle%20%3D%20%2290%2DDay%20Wonder%22%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 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  Create the end date object for the project by using the standard JavaScript new class constructor to create a new instance of the Date class, using the date/time values of the start date. Store the resulting Date in stance in the variable: eDate

 04  Set the date/time value of the end date object to be 90 days from the start date, by using both the getDate(…) and setDate(…) functions placed within the new Date(…) constructor method, to advance the date/time values of the stored ending date object.

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

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

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

 08  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 in 90 days from the beginning of next month. Note the inclusion of a milestone for marking the end of the project.

sDate = new Date().setHours(0,0,0,0) sDate = new Date(new Date(sDate).setDate(1)) sDate = new Date(sDate.setMonth(sDate.getMonth() + 1)) var eDate = new Date(sDate) eDate = new Date(eDate.setDate(eDate.getDate() + 90)) actual.startDate = sDate actual.hasFixedEndDate = false actual.hasGenericDates = false document.project.title = "90-Day Blank" task = actual.rootTask.addSubtask() task.title = "Project End" task.type = TaskType.milestone task.lockedStartDate = eDate
omniplan://localhost/omnijs-run?script=try%7BsDate%20%3D%20new%20Date%28%29%2EsetHours%280%2C0%2C0%2C0%29%0AsDate%20%3D%20new%20Date%28new%20Date%28sDate%29%2EsetDate%281%29%29%0AsDate%20%3D%20new%20Date%28sDate%2EsetMonth%28sDate%2EgetMonth%28%29%20%2B%201%29%29%0Avar%20eDate%20%3D%20new%20Date%28sDate%29%0AeDate%20%3D%20new%20Date%28eDate%2EsetDate%28eDate%2EgetDate%28%29%20%2B%2090%29%29%0Aactual%2EstartDate%20%3D%20sDate%0Aactual%2EhasFixedEndDate%20%3D%20false%0Aactual%2EhasGenericDates%20%3D%20false%0Adocument%2Eproject%2Etitle%20%3D%20%2290%2DDay%20Blank%22%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

 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. Append the setHours(…) instance function to the previous function to set the time of the created date object to midnight. The result will be a date reference in milliseconds (eg: 1556866800000)

 02  Set the day of the date object to be the first of the month, by appending the setDate(…) function (passing-in the value 1) to the date object reconstituted by using the new Date() constructor. Then turn the resulting numeric values into a date object by again using the new Date() constructor.

 03  Advance the mxonth of the starting date object to next month by using the getMonth(…) and setMonth(…) functions.

 04  Create a new date object for the ending date by using the new Date(…) constructor with the starting date object as the passed-in value.

 05  Advance the date of the ending date object 90 days. Since the ending date object was created based upon the starting date object of the 1st of next month, the date of the ending date object will be 90 days from the starting date.

 06  Set the start date of the actual scenario to the stored starting date object.

 07  Set the value of the hasFixedEndDate property to false, indicating that the project length will be calculated from the beginning date.

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

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

 10  Begin the process of creating an ending milestone for the project by using the addSubtask() method to create a new top-level task.

 11  Set the value of the created task’s title property to the desired value.

 12  Set the type of the task to be a milestone.

 13  Set the value of task’s lockedStartDate property to the stored ending date object. You now have a 90-day project that begins at the start of next month!

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