Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ProjectDocument.TaskSelectionChanged event (JavaScript API for Office)

Office Add-ins

Occurs when the task selection changes in the active project.

Last modified: July 06, 2015

Note Note

The name "apps for Office" is changing to "Office Add-ins". During the transition, the documentation and the UI of some Office host applications and Visual Studio tools might still use the term "apps for Office". For details, see New name for apps for Office and SharePoint.

Hosts:

Project

Available in Requirement set

Selection

Added in

1.0

See all support details

Office.EventType.TaskSelectionChanged

TaskSelectionChanged is an EventType enumeration constant that can be used in the ProjectDocument.addHandlerAsync and ProjectDocument.removeHandlerAsync methods to add or remove a handler for the event.

The following code example adds a handler for the TaskSelectionChanged event. When the task selection changes in the document, it gets the GUID of the selected task.

The example assumes your app 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 () {

            // After the DOM is loaded, app-specific code can run.
            Office.context.document.addHandlerAsync(
                Office.EventType.TaskSelectionChanged,
                getTaskGuid);
            getTaskGuid();
        });
    };

    // Get the GUID of the selected task and display it in the app.
    function getTaskGuid() {
        Office.context.document.getSelectedTaskAsync(
            function (result) {
                if (result.status === Office.AsyncResultStatus.Failed) {
                    onError(result.error);
                }
                else {
                    $('#message').html(result.value);
                }
            }
        );
    }

    function onError(error) {
        $('#message').html(error.name + ' ' + error.code + ': ' + error.message);
    }
})();

For a complete code sample that shows how to use a TaskSelectionChanged event handler in a Project app, see Create your first task pane add-in for Project 2013 by using a text editor.

A checkmark (√) in the following matrix indicates that this event is supported in the corresponding Office host application. An empty cell indicates that the Office host application doesn't support this event.

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

Office for Windows desktop

Office Online
(in browser)

Project

Available in requirement sets

Selection

Minimum permission level

Restricted

App types

Task pane

Library

Office.js

Namespace

Office

Version

Changes

1.0

  • Introduced

Show:
© 2015 Microsoft