问题
I am working on building MS Project Web Add-in. Using the below function as a base with other functions I am able to retrieve the task, id and resource name
.
// Get the maximum task index, and then get the task GUIDs.
async getTasks(guids: string[]): Promise<any[]> {
return await Promise.all(
guids.map(async guid => await this.getTask(guid))
);
}
async getTaskGuids(maxIndex: number): Promise<string[]> {
const guids = [];
for (let i = 0; i <= maxIndex; i++) {
guids.push(await this.getTaskGuid(i));
}
return guids;
}
Please see the below screenshot with indentation / sub tasks.
Now I need to identify if the task is sub task or indented task. What is the best way to identify this. Any sample code is really helpful. Kindly help
回答1:
Use the getTaskFieldAsync
method to get specific field values for a task. For example this returns the Outline Level of a task (e.g. 1, 2, 3, etc.):
_projDoc.getTaskFieldAsync(taskGuid, Office.ProjectTaskFields.OutlineLevel,
function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
text.value = text.value + "Outline Level: "
+ asyncResult.value.fieldValue + "\n";
}
else {
logMethodError("getTaskFieldAsync", asyncResult.error.name,
asyncResult.error.message);
}
}
);
Also see the task Summary property to determine if a task is a summary or not. The OutlineChildren collection might also be useful as well as the OutlineParent property.
For reference, see this tutorial on creating a Project add-in using JavaScript.
来源:https://stackoverflow.com/questions/57469675/office-javascript-api-ms-project-identify-parent-task-id-and-sub-task-id