Office Javascript API: MS Project identify parent task id and sub task id

孤人 提交于 2019-12-24 07:38:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!