Docs API Reference

ProjectDocument object

An abstract class that represents the project document (the active project) with which the Office Add-in interacts.

Hosts: Project
Added in 1.0
Office.context.document

Members

Methods

Name Description
addHandlerAsync method Asynchronously adds an event handler for an event in a ProjectDocument object.
getMaxResourceIndexAsync method Asynchronously gets the maximum index of the collection of resources in the current project.
getMaxTaskIndexAsync method Asynchronously gets the maximum index of the collection of tasks in the current project.
getProjectFieldAsync method Asynchronously gets the value of the specified field in the active project.
getResourceByIndexAsync method Asynchronously gets the GUID of the resource that has the specified index in the resource collection.
getResourceFieldAsync method Asynchronously gets the value of the specified field for the specified resource.
getSelectedDataAsync method Asynchronously gets the data that is contained in the current selection of one or more cells in the Gantt chart.
getSelectedResourceAsync method Asynchronously gets the GUID of the selected resource.
getSelectedTaskAsync method Asynchronously gets the GUID of the selected task.
getSelectedViewAsync method Asynchronously gets the view type and name of the active view.
getTaskAsync method Asynchronously gets the task name, the resources that are assigned to the task, and the ID of the task in the synchronized SharePoint task list.
getTaskByIndexAsync method Asynchronously gets the GUID of the task that has the specified index in the task collection.
getTaskFieldAsync method Asynchronously gets the value of the specified field for the specified task.
getWSSUrlAsync method Asynchronously gets the URL of the synchronized SharePoint task list.
removeHandlerAsync method Asynchronously removes an event handler for an event in a ProjectDocument object.
setResourceFieldAsync method Asynchronously sets the value of the specified field for the specified resource.
setTaskFieldAsync method Asynchronously sets the value of the specified field for the specified task.

Events

Name Description
ResourceSelectionChanged event Occurs when the resource selection changes in the active project.
TaskSelectionChanged event Occurs when the task selection changes in the active project.
ViewSelectionChanged event Occurs when the active view changes in the active project.

Remarks

Do not directly call or instantiate the ProjectDocument object in your script.

Example

The following example initializes the add-in and then gets properties of the Document object that are available in the context of a Project document. A Project document is the opened, active project. To access members of the ProjectDocument object, use the Office.context.document object as shown in the code examples for ProjectDocument methods and events.

The example assumes your add-in has a reference to the jQuery library and that the following page control is defined in the content div in the page body:

<span id="message"></span>
(function () {
    "use strict";

    // The initialize function must be run each time a new page is loaded.
    Office.initialize = function (reason) {
        $(document).ready(function () {

            // Get information about the document.
            showDocumentProperties();
        });
    };

    // Get the document mode and the URL of the active project.
    function showDocumentProperties() {
        var output = String.format(
            'The document mode is {0}.<br/>The URL of the active project is {1}.',
            Office.context.document.mode,
            Office.context.document.url);
        $('#message').html(output);
    }
})();

Support details

A capital Y in the following matrix indicates that this object is supported in the corresponding Office host application. An empty cell indicates that the Office host application doesn't support this object.

For more information about Office host application and server requirements, see Requirements for running Office Add-ins.

Office for Windows desktop Office Online (in browser)
Project Y
Add-in types Task pane
Library Office.js
Namespace Office

Support history

Version Changes
1.0 Introduced

See also

Other resources

Task pane add-ins for Project Document object