-1

I did try using the Office.context.document.getSelectedDataAsync(), but I need to click in the row to get the data from the task.

I need to get all tasks without clicking using Javascript inside the Add-in Project.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45

1 Answers1

0

You can find all the available methods described for the Office.Document class in MSDN. The getTaskAsync or getTaskByIndexAsync method allows getting the Task Name, WSS Task Id, and ResourceNames for given taskId:

// Get data for the specified task.
function getTaskAsync() {
    if (taskGuid != undefined) {
        _projDoc.getTaskAsync(
            taskGuid,
            function (asyncResult) {
                if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                    logMethodError("getTaskAsync", asyncResult.error.name,
                               asyncResult.error.message);
                } else {
                    var taskInfo = asyncResult.value;
                    var taskOutput = "Task name: " + taskInfo.taskName +
                                     "\nGUID: " + taskGuid +
                                     "\nWSS Id: " + taskInfo.wssTaskId +
                                     "\nResourceNames: " + taskInfo.resourceNames;
                    text.value = taskOutput;
                }
            }
        );
    } else {
        text.value = 'Task GUID not valid:\n' + taskGuid;
    } 
}

See Create your first task pane add-in for Microsoft Project by using a text editor for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thanks for your answer! But this does not work for me because I need to select the task without clicking and in this example above, it needs to be selected the task to get the taskGuid. It can see in the getSelectedTaskAsync() function when the taskGuid is assigned to use in the other functions later. – George Lucas Oct 19 '22 at 12:56
  • The `Document` object supports the following ways for developers to access document contents. - Selection-based access - Binding-based access – Eugene Astafiev Oct 19 '22 at 20:42
  • Read more about that in the [Common JavaScript API object model](https://learn.microsoft.com/en-us/office/dev/add-ins/develop/office-javascript-api-object-model) article. – Eugene Astafiev Oct 19 '22 at 20:43