OneNote.Application class

Represents the top-level object that contains all globally addressable OneNote objects such as notebooks, the active notebook, and the active section.

[ API set: OneNoteApi 1.1 ]

Extends

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

notebooks

Gets the collection of notebooks that are open in the OneNote application instance. In OneNote Online, only one notebook at a time is open in the application instance. Read-only.

[ API set: OneNoteApi 1.1 ]

Methods

getActiveNotebook()

Gets the active notebook if one exists. If no notebook is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveNotebookOrNull()

Gets the active notebook if one exists. If no notebook is active, returns null.

[ API set: OneNoteApi 1.1 ]

getActiveOutline()

Gets the active outline if one exists, If no outline is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveOutlineOrNull()

Gets the active outline if one exists, otherwise returns null.

[ API set: OneNoteApi 1.1 ]

getActivePage()

Gets the active page if one exists. If no page is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActivePageOrNull()

Gets the active page if one exists. If no page is active, returns null.

[ API set: OneNoteApi 1.1 ]

getActiveParagraph()

Gets the active Paragraph if one exists, If no Paragraph is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveParagraphOrNull()

Gets the active Paragraph if one exists, otherwise returns null.

[ API set: OneNoteApi 1.1 ]

getActiveSection()

Gets the active section if one exists. If no section is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveSectionOrNull()

Gets the active section if one exists. If no section is active, returns null.

[ API set: OneNoteApi 1.1 ]

getWindowSize()
insertHtmlAtCurrentPosition(html)
isViewingDeletedNotes()
load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

navigateToPage(page)

Opens the specified page in the application instance.

[ API set: OneNoteApi 1.1 ]

navigateToPageWithClientUrl(url)

Gets the specified page, and opens it in the application instance.

[ API set: OneNoteApi 1.1 ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original OneNote.Application object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.ApplicationData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

RequestContext

notebooks

Gets the collection of notebooks that are open in the OneNote application instance. In OneNote Online, only one notebook at a time is open in the application instance. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly notebooks: OneNote.NotebookCollection;

Property Value

Method Details

getActiveNotebook()

Gets the active notebook if one exists. If no notebook is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveNotebook(): OneNote.Notebook;

Returns

Examples

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

getActiveNotebookOrNull()

Gets the active notebook if one exists. If no notebook is active, returns null.

[ API set: OneNoteApi 1.1 ]

getActiveNotebookOrNull(): OneNote.Notebook;

Returns

Examples

OneNote.run(function (context) {

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

    // 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 () {

            // check if active notebook is set.
            if (!notebook.isNull) {
                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));
    }
});

getActiveOutline()

Gets the active outline if one exists, If no outline is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveOutline(): OneNote.Outline;

Returns

Examples

OneNote.run(function (context) {

    // get active outline.
    var outline = context.application.getActiveOutline();

    // Queue a command to load the id of the outline.         
    outline.load('id');

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

            // Show some properties.
            console.log("outline id: " + outline.id);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getActiveOutlineOrNull()

Gets the active outline if one exists, otherwise returns null.

[ API set: OneNoteApi 1.1 ]

getActiveOutlineOrNull(): OneNote.Outline;

Returns

Examples

OneNote.run(function (context) {

    // get active outline.
    var outline = context.application.getActiveOutlineOrNull();

    // Queue a command to load the id of the outline.         
    outline.load('id');

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

            if (!outline.isNull) {
                console.log("outline id: " + outline.id);
            }
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getActivePage()

Gets the active page if one exists. If no page is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActivePage(): OneNote.Page;

Returns

Examples

OneNote.run(function (context) {

    // Get the active page.
    var page = context.application.getActivePage();

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

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

            // Show some properties.
            console.log("Page title: " + page.title);
            console.log("Page ID: " + page.id);

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

getActivePageOrNull()

Gets the active page if one exists. If no page is active, returns null.

[ API set: OneNoteApi 1.1 ]

getActivePageOrNull(): OneNote.Page;

Returns

Examples

OneNote.run(function (context) {

    // Get the active page.
    var page = context.application.getActivePageOrNull();

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

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

            if (!page.isNull) {
                // Show some properties.
                console.log("Page title: " + page.title);
                console.log("Page ID: " + page.id);
            }
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getActiveParagraph()

Gets the active Paragraph if one exists, If no Paragraph is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveParagraph(): OneNote.Paragraph;

Returns

getActiveParagraphOrNull()

Gets the active Paragraph if one exists, otherwise returns null.

[ API set: OneNoteApi 1.1 ]

getActiveParagraphOrNull(): OneNote.Paragraph;

Returns

getActiveSection()

Gets the active section if one exists. If no section is active, throws ItemNotFound.

[ API set: OneNoteApi 1.1 ]

getActiveSection(): OneNote.Section;

Returns

Examples

OneNote.run(function (context) {

    // Get the active section.
    var section = context.application.getActiveSection();

    // Queue a command to load the section. 
    // For best performance, request specific properties.           
    section.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("Section name: " + section.name);
            console.log("Section ID: " + section.id);

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

getActiveSectionOrNull()

Gets the active section if one exists. If no section is active, returns null.

[ API set: OneNoteApi 1.1 ]

getActiveSectionOrNull(): OneNote.Section;

Returns

Examples

OneNote.run(function (context) {

    // Get the active section.
    var section = context.application.getActiveSectionOrNull();

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

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function () {
            if (!section.isNull) {
                // Show some properties.
                console.log("Section name: " + section.name);
                console.log("Section ID: " + section.id);
            }
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getWindowSize()

getWindowSize(): OfficeExtension.ClientResult<number[]>;

Returns

OfficeExtension.ClientResult<number[]>

insertHtmlAtCurrentPosition(html)

insertHtmlAtCurrentPosition(html: string): void;

Parameters

html
string

Returns

void

isViewingDeletedNotes()

isViewingDeletedNotes(): OfficeExtension.ClientResult<boolean>;

Returns

OfficeExtension.ClientResult<boolean>

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: OneNote.Interfaces.ApplicationLoadOptions): OneNote.Application;

Parameters

option
OneNote.Interfaces.ApplicationLoadOptions

Returns

OneNote.Application

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): OneNote.Application - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): OneNote.Application - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): OneNote.Application - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): OneNote.Application;

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

OneNote.Application

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: { select?: string; expand?: string; }): OneNote.Application;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

Where propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

OneNote.Application

Opens the specified page in the application instance.

[ API set: OneNoteApi 1.1 ]

navigateToPage(page: OneNote.Page): void;

Parameters

page
OneNote.Page

The page to open.

Returns

void

Examples

OneNote.run(function (context) {

    // Get the pages in the current section.
    var pages = context.application.getActiveSection().pages;

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

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

            // This example loads the first page in the section.
            var page = pages.items[0];

            // Open the page in the application.                    
            context.application.navigateToPage(page);

            // Run the queued command.
            return context.sync();
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

Gets the specified page, and opens it in the application instance.

[ API set: OneNoteApi 1.1 ]

navigateToPageWithClientUrl(url: string): OneNote.Page;

Parameters

url
string

The client url of the page to open.

Returns

Examples

OneNote.run(function (context) {

    // Get the pages in the current section.
    var pages = context.application.getActiveSection().pages;

    // Queue a command to load the pages. 
    // For best performance, request specific properties.           
    pages.load('clientUrl');

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

            // This example loads the first page in the section.
            var page = pages.items[0];

            // Open the page in the application.                    
            context.application.navigateToPageWithClientUrl(page.clientUrl);

            // Run the queued command.
            return context.sync();
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original OneNote.Application object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.ApplicationData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): OneNote.Interfaces.ApplicationData;

Returns

OneNote.Interfaces.ApplicationData