This topic has not yet been rated - Rate this topic

ProjectDocument.getProjectFieldAsync method (Project apps)

apps for SharePoint

Published: February 26, 2013

Asynchronously gets the value of the specified field in the active project.

Office.context.document.getProjectFieldAsync(fieldId [,options], callback);
fieldId

Integer value of the field identification number, can be a constant from the ProjectProjectFields enumeration. Required.

options

Type: object

Specifies the following optional parameters.

asyncContext

Type: array, boolean, null, number, object, string, or undefined

A user-defined item of any type that is returned in the AsyncResult object without being altered. Optional.

callback

Type: object

A function with a parameter of type AsyncResult for the returned data, which is invoked when the callback returns. Required.

When the function that you pass to the callback parameter executes, it receives an AsyncResult object that you can access from the parameter in the callback function. The AsyncResult.value object contains the following property:

  • The fieldValue property is the value of the project field.

To determine the success or failure of the operation, use the AsyncResult.status property. If the operation fails, use the AsyncResult.error property to access an Error object that provides information about the error.

In the following example, the getProjectFields function calls getProjectFieldAsync twice to get the GUID and the start date of the active project.

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;
    });
}

function getProjectFields() {
    textBox.value = "";

    _projDoc.getProjectFieldAsync(Office.ProjectProjectFields.GUID,
        function (asyncResult) {
            if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
                textBox.value = "Project GUID: " + asyncResult.value.fieldValue + "\n";
            }
            else {
                var error = asyncResult.error;
                textBox.value = error.name + ': ' + error.message;
            }
        }
    );

    _projDoc.getProjectFieldAsync(Office.ProjectProjectFields.Start,
        function (asyncResult) {
            if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
                textBox.value = textBox.value + "\nStart: " + asyncResult.value.fieldValue + "\n";
            }
            else {
                var error = asyncResult.error;
                textBox.value = error.name + ': ' + error.message;
            }
        }
    );
}

For example, the textbox in the app task pane shows:

Project GUID: 14D3E03B-9A7D-E111-92FC-00155D3BA208
Start: Tue 4/3/12

Supported clients

Project Standard 2013 and Project Professional 2013

Libraries

Office.js, Project-15.js

Namespace

Office

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.