In PLM Scripting, the built-in object under item matching the Project Management tab is Project object. An Array of Project objects will be returned by calling item.project.subTasks. They give you all the projects of the item. The item here must be an instance of Item.
Basically a project task can be divided into three classes: text task, linked task and milestone task. In scripting, all of them are represented using Project object, but there is some difference when we deal with each of them. In this post, let’s talk about what the common ground they have and what the difference between them.
Text project task
A text project task is a task not linked to any item. Its title is given by user.
var textTask = item.project.subTasks;
// r/w title
textTask.title = ‘new title’;
// r/w start date of project
textTask.start_date = new Date();
// r/w end date of project
textTask.end_date = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
// r/w progress, must be in [0, 100]
textTask.progress = 50;
// read duration
var duration = textTask.duration;
// read owner, the parent item of the project
var owner = textTask.owner;
Linked project task
A linked project task is a task linking to an item. It also has the same properties as a text project task, however the title property will be the linked item’s descriptor instead of the text defined by the user. The linked item can be gotten via linkedTask.item.
var linkedTask = item.project.subTasks;
// read linked item. An Item object is returned
var linkedItem = linkedTask.item;
Milestone project task (Read-only task)
If a linked project contains milestones, then we call it a milestone project task, or a read-only project task because all the properties of it are read-only. That’s the only difference between linked task and milestone task.
Create project task
The general form to create a task is:
new Task(Title/LinkedItem[, StartDate[, EndDate[,Progress]]]);
The square brackets parts are optional. The default value for both start and end dates is today, and the default progress is 0.
Create a text task:
// create a text task
var newTextTask = new Task(‘Text Task’, new Date(), new Date(new Date().getTime() + 24 * 60 * 60 * 1000), 0);
// add task into array
Create a linked/read-only task:
// fetch item to be linked
var itemToBeLinked = loadItem(1234);
// create linked task, leave the rest parameters default
var newLinkedTask = new Task(itemToBeLinked);
// add new task into array