0
votes

How to get the currently viewed notebook from onenote2016.

Application.OnenoteApplication.GetHierarchy() brings the top book listed in the notebooks.

isCurrentlyViewed attribute is "True" for all notebook listed in the Notebook list in onenote. When one:Page[@isCurrentlyViewed=\"true\"]" will change to false.

2

2 Answers

0
votes

Use "GetActiveNotebook" https://github.com/OfficeDev/office-js-docs/blob/master/reference/onenote/application.md#getactivenotebook

OneNote.run(function (context) {

    // Get the active notebook.
    var notebook = context.application.getActiveNotebook();

    // Queue a command to load the notebook. 
    // For best performance, request specific properties.           
    notebook.load('id,name');

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function () {

            // Show some properties.
            console.log("Notebook name: " + notebook.name);
            console.log("Notebook ID: " + notebook.id);

        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
0
votes

Try: Application.Windows.CurrentWindow.CurrentNotebookId that will get you the current notebook ID.