Build your first Project task pane add-in

In this article, you'll walk through the process of building a Project task pane add-in.

Prerequisites

  • Node.js (version 8.0.0 or later)

  • The latest version of Yeoman and the Yeoman generator for Office Add-ins. To install these tools globally, run the following command via the command prompt:

    npm install -g yo generator-office
    

    Note

    Even if you've previously installed the Yeoman generator, we recommend you update your package to the latest version from npm.

  • Project 2016 or later on Windows

Create the add-in

Use the Yeoman generator to create a Project add-in project. Run the following command and then answer the prompts as follows:

yo office
  • Choose a project type: Office Add-in Task Pane project
  • Choose a script type: Javascript
  • What do you want to name your add-in? My Office Add-in
  • Which Office client application would you like to support? Project

A screenshot of the prompts and answers for the Yeoman generator

After you complete the wizard, the generator creates the project and installs supporting Node components.

Explore the project

The add-in project that you've created with the Yeoman generator contains sample code for a very basic task pane add-in.

  • The ./manifest.xml file in the root directory of the project defines the settings and capabilities of the add-in.
  • The ./src/taskpane/taskpane.html file contains the HTML markup for the task pane.
  • The ./src/taskpane/taskpane.css file contains the CSS that's applied to content in the task pane.
  • The ./src/taskpane/taskpane.js file contains the Office JavaScript API code that facilitates interaction between the task pane and the Office host application.

Update the code

In your code editor, open the file ./src/taskpane/taskpane.js and add the following code within the run function. This code uses the Office JavaScript API to set the Name field and Notes field of the selected task.

var taskGuid;

// Get the GUID of the selected task
Office.context.document.getSelectedTaskAsync(
    function (result) {
        if (result.status === Office.AsyncResultStatus.Succeeded) {
            taskGuid = result.value;

            // Set the specified fields for the selected task.
            var targetFields = [Office.ProjectTaskFields.Name, Office.ProjectTaskFields.Notes];
            var fieldValues = ['New task name', 'Notes for the task.'];

            // Set the field value. If the call is successful, set the next field.
            for (var i = 0; i < targetFields.length; i++) {
                Office.context.document.setTaskFieldAsync(
                    taskGuid,
                    targetFields[i],
                    fieldValues[i],
                    function (result) {
                        if (result.status === Office.AsyncResultStatus.Succeeded) {
                            i++;
                        }
                        else {
                            var err = result.error;
                            console.log(err.name + ' ' + err.code + ' ' + err.message);
                        }
                    }
                );
            }
        } else {
            var err = result.error;
            console.log(err.name + ' ' + err.code + ' ' + err.message);
        }
    }
);

Try it out

  1. Navigate to the root folder of the project.

    cd "My Office Add-in"
    
  2. Start the local web server.

    Note

    Office Add-ins should use HTTPS, not HTTP, even when you are developing. If you are prompted to install a certificate after you run the following command, accept the prompt to install the certificate that the Yeoman generator provides.

    Run the following command in the root directory of your project. When you run this command, the local web server will start.

    npm start
    
  3. In Project, create a simple project plan.

  4. Load your add-in in Project by following the instructions in Sideload Office Add-ins on Windows.

  5. Select a single task within the project.

  6. At the bottom of the task pane, choose the Run link to rename the selected task and add notes to the selected task.

    Screenshot of the Project application with the task pane add-in loaded

Next steps

Congratulations, you've successfully created a Project task pane add-in! Next, learn more about the capabilities of a Project add-in and explore common scenarios.