ProjectDocument.TaskSelectionChanged event (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

Occurs when the task selection changes in the active project.

Last modified: February 26, 2014

The TaskSelectionChanged event is an EventType enumeration constant that can be used in a user-defined function that adds or removes an event handler.


The Project-15.js file extends the Office.EventType enumeration to include the TaskSelectionChanged event. An event handler for the TaskSelectionChanged event can be added by using the addHandlerAsync method. After an event handler is added, it can be removed by using the removeHandlerAsync method. For more information, see the ProjectDocument.addHandlerAsync method.

In the following example, the addTaskEventHandler function calls the manageEventHandlerAsync function to add the onTaskSelectionChanged event handler for the Office.EventType.TaskSelectionChanged event. Similarly, the removeTaskEventHandler function calls manageEventHandlerAsync to remove the event handler.

In the following code, the textBox object is a reference to a textarea control in an HTML file, for example: <textarea id="textBox" rows="6" cols="25"></textarea>

var _projDoc;

// The initialize function is required for all apps.
Office.initialize = function (reason) {
    // Checks for the DOM to load using the jQuery ready function.
    $(document).ready(function () {
    // After the DOM is loaded, app-specific code can run.
    _projDoc = Office.context.document;

// Task selection changed event handler.
function onTaskSelectionChanged(eventArgs) {
    textBox.value = "In task selection change event handler";

// Add or remove the specified event handler.
function manageEventHandlerAsync(eventType, handler, operation) {
    _projDoc[operation]   //The operation is addHandlerAsync or removeHandlerAsync.
        { handler: handler },
        function (asyncResult) {
            var message = "Operation: " + operation;
            message = message + "\nStatus: " + asyncResult.status + "\n";
            textBox.value = message;

// Add a task selection changed event handler.
function addTaskEventHandler() {
        Office.EventType.TaskSelectionChanged, // The task selection changed event.
        onTaskSelectionChanged,                // The event handler.
        'addHandlerAsync'                      // The method to add an event handler.

// Remove a task selection changed event handler.
function removeTaskEventHandler() {

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

Supported clients

Project Standard 2013, Project Professional 2013, and Project 2013 SP1


Office.js, Project-15.js



© 2014 Microsoft