Export (0) Print
Expand All

ProjectDocument.getSelectedResourceAsync method (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

Asynchronously gets the GUID of the selected resource.

Last modified: June 12, 2014

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


Type: object

Specifies the following optional parameters.


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.


Type: object

A function with a parameter of type AsyncResult, 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. Use the AsyncResult.value property to get the GUID of the selected resource. The GUID value is a string.

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.

The GUID of a resource is more useful in Project apps than the resource name. The resource GUID can be used to access resource information in Project Server, such as data about resources in Project Online that is available through the client-side object model (CSOM).

If you save the resource GUID in a local variable, you can also use it as a parameter for the getResourceFieldAsync method.

Note Note

If no resource is selected in one of the views that show resources, for example the Resource Sheet view or the Resource Usage view, the getSelectedResourceAsync function returns an error.

In the following example, the showResourceGuid function uses an anonymous function as the callback parameter. The callback function shows the text value of the GUID for the selected resource.

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;
var resourceGuid;

// 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 showResourceGuid() {
        function (asyncResult) {
            if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                var error = asyncResult.error;
                textBox.value = error.name + ': ' + error.message;
            } else {
                var resourceGuid = asyncResult.value;
                textBox.value = 'GUID of selected resource:\n' + resourceGuid;

Supported clients

Project Standard 2013, Project Professional 2013, PowerPoint 2013 SP1, PowerPoint 2013 RT


Office.js, Project-15.js



© 2014 Microsoft