Resources

An OmniPlan project includes the team members, equipment and materials needed to bring the project to fruition. Every person, piece of infrastructure, and raw ingredient that contributes to reaching the project’s goal is counted as a resource.

Creating resources works much like creating tasks. Like tasks, resources can also exist in hierarchical groups.

Instance Properties

Here are the properties of an OmmiPlan resource:

Instance Functions

Here are the functions that can be called on an instance of a Resource.

Resource Types

Here are the various types of OmniPlan resources:

rsc = actual.rootResource.addMember() rsc.type = ResourceType.equipment rsc.name = "Backhoe" rsc.costPerHour = 275
omniplan://localhost/omnijs-run?script=try%7Brsc%20%3D%20actual%2ErootResource%2EaddMember%28%29%0Arsc%2Etype%20%3D%20ResourceType%2Eequipment%0Arsc%2Ename%20%3D%20%22Backhoe%22%0Arsc%2EcostPerHour%20%3D%20275%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

Resource Assignment Types

The process of adjusting project resources can effect interaction with other project elements. Resource Assignment Types determine the method used in calculating any adjustments.

rsc = actual.resourceNamed("Bob Jones") if(rsc){ task = actual.rootTask.addSubtask() task.addAssignment(rsc) task.resourceAssignmentType = ResourceAssignmentType.adjustAssignedUnits }

Generating a Reference to a Resource

To generate a reference to a specific resource, use the resourceNamed("resourceName") function of the Scenario class. Pass-in the name of the resource to the function called on a scenario (actual or baseline) and the result will be either a reference to the first matching resource, or null — indicating that no matching resource was located:

In the following example, a reference to the specified resource is generated and used to assign the resource to a new task:

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

Here’s a script variation that creates a resource if one doesn’t already exist:

resourceName = "Bob Sykes" rsc = actual.resourceNamed(resourceName) if(!rsc){ rsc = actual.rootResource.addMember() rsc.name = resourceName }

Import People Data from File

This Omni Automation action plugIn will create new staff resources using the data read from either a chosen TSV (tabbed-delimited) or CSV (comma-separated) file.

Note that the action plugIn incorporates the use of the FilePicker class to enable the user to choose the file to import.

Also note that, for this example plugIn, the exported data has two columns: the staffer’s full name, and the staffer’s email address. (DOWNLOAD EXAMPLE FILES)

/*{ "type": "action", "targets": ["omniplan"], "author": "Otto Automator", "identifier": "com.omni-automation.import-people-from-file", "version": "1.0", "description": "Will create new resources using the person data read from a chosen comma- or tab-delimited file.", "label": "Import People from File", "shortLabel": "Import People" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: project, tasks, resources // CREATE INSTANCE OF FILEPICKER var picker = new FilePicker() picker.folders = false picker.multiple = false TSVtype = new FileType("public.tab-separated-values-text") CSVtype = new FileType("public.comma-separated-values-text") picker.types = [TSVtype,CSVtype] // DECLARE THE PROMISE VARIABLE var pickerPromise // CHECK PLATFORM if(app.platformName === "iOS"){ msg = "Tap ”Continue” and choose the comma- or tab-delimited text file to import from the forthcoming file picker:" var alert = new Alert("Select File", msg) alert.addOption("Continue") alert.show(function(result){ pickerPromise = picker.show() }) } else if (app.platformName === "macOS"){ picker.message = "Choose the comma- or tab-delimited text file to import:" pickerPromise = picker.show() } // READ AND PROCESS CONTENTS OF THE CHOSEN TEXT FILE pickerPromise.then(function(urls){ url = urls[0] var typeIndicator = (url.string.endsWith(".tsv")) ? 0:1 url.fetch(function(data){ data = data.toString().split(/\r?\n/) var items = new Array() for(var i = 0; i < data.length; i++){ if(typeIndicator === 0){ items.push(data[i].split(/\t/)) } else { items.push(data[i].split(",")) } } // GET THE CURRENT RESOURCE EMAIL ADDRESSES var resourceEmails = new Array() actual.rootResource.descendents().forEach((rsc)=>{ if (rsc.type === ResourceType.staff && rsc.email){ resourceEmails.push(rsc.email) } }) // CREATE NEW RESOURCE FOR EACH UNIQUE ITEM items.forEach((item)=>{ // TRIM ENCASING QUOTES IF SOURCE IS CSV var personName = (typeIndicator === 0) ? item[0]:item[0].replace(/^\"+|\"+$/gm,'') var personEmail = (typeIndicator === 0) ? item[1]:item[1].replace(/^\"+|\"+$/gm,'') // ADD PERSONS WITH UNIQUE EMAIL AS RESOURCES if (!resourceEmails.includes(personEmail)){ newResource = actual.rootResource.addMember() newResource.type = ResourceType.staff newResource.name = personName newResource.email = personEmail resourceEmails.push(personEmail) } }) }) }) }); action.validate = function(selection, sender){ // validation code // selection options: project, tasks, resources return true }; return action; }(); _;

 01-10  The action metadata determines which Omni applications are targeted by the action, the action’s Automation menu and toolbar titles, and the version and description of the action.

 11-82  The main function that contains the action code.

 12-73  Create a new instance of the Action class that includes a callback function that receives references to the selection and sender objects as its default parameters.

 17  Create and store an instance of the FilePicker class.

 18-19  Set the properties of the file picker to allow the selection of a single file.

 20-21  Create instances of the FileType class for files that contain either comma-separated-values or tab-separated-values.

 22  Assign the file types of the file picker instance to the created file types.

 24  Declare a variable that will contain the JavaScript promise object that is returned when the file picker is called.

 38-71  Calling the then() function on promise object will enable the processing of the chosen file, whose file URL is passed as an array into the callback function.

 39  The file URL for the chosen file is extracted from the passed URL array (the passed-in array contains a single-item)

 40  A JavaScript ternary statement returns a value of 0 if the file URL ends with “tsv” or 1 if the file URL ends with “csv.”

 41-70  The fetch() function is used to extract the data from the file, and passes the data object into the callback function.

 42  Convert the passed-in data to text and then delimit it by paragraphs or linefeeds into an array of text objects.

 43  Create an empty array to hold the split data objects.

 44-50  Iterate the array of text objects and split each one based upon whether the data of the source file was tab- or comma-delimited. The resulting JavaScript object will contain two text items, and will be appended to the previously created array.

 51-57  To ensure that duplicate resources are not created, generate a list of the existing resource emails, which will be used for comparison before creating a new resource.

 52-69  Use the JavaScript forEach() function to create new resources using the data from each of the retrieved text pairs.

 53-54  If the source data was comma-delimited, strip the encasing quotes from each text string of the object.

 63-68  If the potential email address is not in the list of existing resource emails, then create a new resource set its name and email address.

 67  Append the email address of the created resource to the list of current email addresses.

 75-79  The resulting boolean value of the validation function determines whether the action plugIn appears in the Automation menu.

Resource Groups

A Resource Group is a resource that contains other resources. It is often used to create “teams” assigned to specific tasks.

The following script example creates resource groups for the teams imported from a chosen JSON data file (DOWNLOAD) (example data generated by mockaroo.com)

[ { "name": "Red Team", "members": [ { "email": "ldell4@xinhuanet.com", "phone": "800-604-1071", "name": "Lewes Dell 'Orto", "role": "Food Chemist" }, { "email": "mcovendon3@symantec.com", "phone": "694-301-1238", "name": "Markos Covendon", "role": "Programmer Analyst I" }, { "email": "swolton2@freewebs.com", "phone": "793-362-0138", "name": "Sylas Wolton", "role": "Developer IV" }, { "email": "sstockport1@squarespace.com", "phone": "215-981-3559", "name": "Shirlene Stockport", "role": "Product Engineer" }, { "email": "bgerant0@ucoz.ru", "phone": "373-419-0679", "name": "Biron Gerant", "role": "VP Sales" } ] }, { "name": "Blue Team", "members": [ { "email": "fbaugham9@people.com.cn", "phone": "486-110-7943", "name": "Farris Baugham", "role": "Nurse" }, { "email": "sbird8@gnu.org", "phone": "511-593-7065", "name": "Sonnnie Bird", "role": "Research Associate" }, { "email": "hstangroom7@howstuffworks.com", "phone": "324-905-1600", "name": "Hill Stangroom", "role": "Marketing Manager" }, { "email": "tchislett6@yelp.com", "phone": "929-853-7355", "name": "Thebault Chislett", "role": "Editor" }, { "email": "edurand5@imageshack.us", "phone": "515-924-8322", "name": "Eldredge Durand", "role": "Food Chemist" } ] }, { "name": "Green Team", "members": [ { "email": "ciaduccellie@time.com", "phone": "862-281-2490", "name": "Clarke Iaduccelli", "role": "Environmental Tech" }, { "email": "ajankiewiczd@symantec.com", "phone": "355-390-3438", "name": "Angelica Jankiewicz", "role": "Junior Executive" }, { "email": "dpackc@mediafire.com", "phone": "604-389-5099", "name": "Debee Pack", "role": "Account Executive" }, { "email": "kmaturab@opensource.org", "phone": "993-456-9106", "name": "Kala Matura", "role": "GIS Technical Architect" }, { "email": "jpadricka@istockphoto.com", "phone": "282-371-9596", "name": "Johnette Padrick", "role": "Internal Auditor" } ] }, { "name": "Orange Team", "members": [ { "email": "ejouhanj@springer.com", "phone": "280-668-5317", "name": "Ephrayim Jouhan", "role": "Chemical Engineer" }, { "email": "hblagbroughi@nydailynews.com", "phone": "299-880-0063", "name": "Hermione Blagbrough", "role": "VP Accounting" }, { "email": "kvanbrughh@nymag.com", "phone": "631-123-6111", "name": "Kris VanBrugh", "role": "VP Marketing" }, { "email": "ldoriang@friendfeed.com", "phone": "498-262-5636", "name": "Lowrance Dorian", "role": "Account Coordinator" }, { "email": "pmewsf@adobe.com", "phone": "614-164-0036", "name": "Pearl Mews", "role": "Web Developer IV" } ] } ]
var picker = new FilePicker() picker.folders = false picker.multiple = false picker.types = [FileType.json] picker.show().then(function(urlsArray){ aURL = urlsArray[0] aURL.fetch(function(data){ resourceData = JSON.parse(data.toString()) resourceData.forEach((team)=>{ rsc = actual.rootResource.addMember() rsc.type = ResourceType.group rsc.name = team["name"] staff = team["members"] staff.forEach((staffer)=>{ teammate = rsc.addMember() teammate.type = ResourceType.staff teammate.name = staffer["name"] teammate.email = staffer["email"] teammate.note = staffer["role"] }) }) }) })
omniplan://localhost/omnijs-run?script=try%7Bvar%20picker%20%3D%20new%20FilePicker%28%29%0Apicker%2Efolders%20%3D%20false%0Apicker%2Emultiple%20%3D%20false%0Apicker%2Etypes%20%3D%20%5BFileType%2Ejson%5D%0Apicker%2Eshow%28%29%2Ethen%28function%28urlsArray%29%7B%0A%09aURL%20%3D%20urlsArray%5B0%5D%0A%09aURL%2Efetch%28function%28data%29%7B%0A%09%09resourceData%20%3D%20JSON%2Eparse%28data%2EtoString%28%29%29%0A%09%09resourceData%2EforEach%28%28team%29%3D%3E%7B%0A%09%09%09rsc%20%3D%20actual%2ErootResource%2EaddMember%28%29%0A%09%09%09rsc%2Etype%20%3D%20ResourceType%2Egroup%0A%09%09%09rsc%2Ename%20%3D%20team%5B%22name%22%5D%0A%09%09%09staff%20%3D%20team%5B%22members%22%5D%0A%09%09%09staff%2EforEach%28%28staffer%29%3D%3E%7B%0A%09%09%09%09teammate%20%3D%20rsc%2EaddMember%28%29%0A%09%09%09%09teammate%2Etype%20%3D%20ResourceType%2Estaff%0A%09%09%09%09teammate%2Ename%20%3D%20staffer%5B%22name%22%5D%0A%09%09%09%09teammate%2Eemail%20%3D%20staffer%5B%22email%22%5D%0A%09%09%09%09teammate%2Enote%20%3D%20staffer%5B%22role%22%5D%0A%09%09%09%7D%29%0A%09%09%7D%29%0A%09%7D%29%0A%7D%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

 01  Store an new instance of the FilePicker class in the variable: filepicker

 02-04  Set the properties of the file picker to accept a single JSON file as the selection.

 05  Use the show() method to display the file picker interface. The result of this command is a JavaScript promise.

 05-21  Append the then() function to the show() method to process the promise result of the file picker. The then() callback function will receive an array of URLs to the chosen items as its default parameter.

 06  The file URL to the chosen JSON file will be the only item in the passed array of URLs.

 07-20  Call the fetch() function on the file URL to extract its contents and pass the resulting data to the function.

 08  Use the JavaScript toString() function to convert the file data to text, and then call the parse() method of of the JSON class to convert the text into a JSON array of objects (in this case the “teams” of people).

 09-19  Iterate the JSON array of “team” objects.

 10  Create a new resource.

 11  Set the type of the new resource to group.

 12  Set the name of the new resource group to the name of the team.

 13  Extract the array of team member objects from the JSON team object

 14-18  Use the JavaScript forEach() function to process each of the team member JSON objects.

 15  Add a new resource to the group resource.

 16  Set the type of the new resource to be a staff resource.

 17  Assign the name of the new staff resource to the name of the team member.

 18  Assign the email of the new staff resource to the email of the team member.

 19  Assign the note of the new staff resource to the role of the team member.

imported-resource-groups
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