OneNote.SectionGroup class

Represents a OneNote section group. Section groups can contain sections and other section groups.

[ API set: OneNoteApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

clientUrl

The client url of the section group. Read only

[ API set: OneNoteApi 1.1 ]

id

Gets the ID of the section group. Read-only.

[ API set: OneNoteApi 1.1 ]

name

Gets the name of the section group. Read-only.

[ API set: OneNoteApi 1.1 ]

notebook

Gets the notebook that contains the section group. Read-only.

[ API set: OneNoteApi 1.1 ]

parentSectionGroup

Gets the section group that contains the section group. Throws ItemNotFound if the section group is a direct child of the notebook. Read-only.

[ API set: OneNoteApi 1.1 ]

parentSectionGroupOrNull

Gets the section group that contains the section group. Returns null if the section group is a direct child of the notebook. Read-only.

[ API set: OneNoteApi 1.1 ]

sectionGroups

The collection of section groups in the section group. Read only

[ API set: OneNoteApi 1.1 ]

sections

The collection of sections in the section group. Read only

[ API set: OneNoteApi 1.1 ]

Methods

addSection(title)

Adds a new section to the end of the section group.

[ API set: OneNoteApi 1.1 ]

addSectionGroup(name)

Adds a new section group to the end of this sectionGroup.

[ API set: OneNoteApi 1.1 ]

getRestApiId()

Gets the REST API ID.

[ API set: OneNoteApi 1.1 ]

load(option)

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

toJSON()
track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you are using this object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created.

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect.

Property Details

clientUrl

The client url of the section group. Read only

[ API set: OneNoteApi 1.1 ]

readonly clientUrl: string;

Property Value

string

id

Gets the ID of the section group. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;

Property Value

string

name

Gets the name of the section group. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly name: string;

Property Value

string

notebook

Gets the notebook that contains the section group. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly notebook: OneNote.Notebook;

Property Value

parentSectionGroup

Gets the section group that contains the section group. Throws ItemNotFound if the section group is a direct child of the notebook. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentSectionGroup: OneNote.SectionGroup;

Property Value

parentSectionGroupOrNull

Gets the section group that contains the section group. Returns null if the section group is a direct child of the notebook. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentSectionGroupOrNull: OneNote.SectionGroup;

Property Value

sectionGroups

The collection of section groups in the section group. Read only

[ API set: OneNoteApi 1.1 ]

readonly sectionGroups: OneNote.SectionGroupCollection;

Property Value

sections

The collection of sections in the section group. Read only

[ API set: OneNoteApi 1.1 ]

readonly sections: OneNote.SectionCollection;

Property Value

Method Details

addSection(title)

Adds a new section to the end of the section group.

[ API set: OneNoteApi 1.1 ]

addSection(title: string): OneNote.Section;

Parameters

title
string

The name of the new section.

Returns

Examples

OneNote.run(function (context) {

    // Get the section groups that are direct children of the current notebook.
    var sectionGroups = context.application.getActiveNotebook().sectionGroups;

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

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

            // Add a section to each section group.
            $.each(sectionGroups.items, function(index, sectionGroup) {
                sectionGroup.addSection("Agenda");
            });

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

addSectionGroup(name)

Adds a new section group to the end of this sectionGroup.

[ API set: OneNoteApi 1.1 ]

addSectionGroup(name: string): OneNote.SectionGroup;

Parameters

name
string

The name of the new section.

Returns

Examples

OneNote.run(function (context) {
    var sectionGroup;
    var nestedSectionGroup;

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

    // Queue a command to add a new section group.
    var sectionGroups = notebook.sectionGroups;

    // Queue a command to load the new section group.
    sectionGroups.load();

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function(){
            sectionGroup = sectionGroups.items[0];
            sectionGroup.load();
            return context.sync();
        })
        .then(function(){
            nestedSectionGroup = sectionGroup.addSectionGroup("Sample nested section group");
            nestedSectionGroup.load();
            return context.sync();
        })
        .then(function() {
            console.log("New nested section group name is " + nestedSectionGroup.name);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
}); 

getRestApiId()

Gets the REST API ID.

[ API set: OneNoteApi 1.1 ]

getRestApiId(): OfficeExtension.ClientResult<string>;

Returns

OfficeExtension.ClientResult<string>

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?: string | string[]): OneNote.SectionGroup;

Parameters

option
string | string[]

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

Returns

Remarks

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

load(option?: { select?: string; expand?: string; }): OneNote.SectionGroup - 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.SectionGroup - 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.

Examples

OneNote.run(function (context) {

    // Get the parent section group that contains the current section.
    var sectionGroup = context.application.getActiveSection().parentSectionGroup;

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

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

            // Write the properties.
            console.log("Section group name: " + sectionGroup.name);
            console.log("Section group ID: " + sectionGroup.id);

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

    // Get the parent section group that contains the current section.
    var sectionGroup = context.application.getActiveSection().parentSectionGroup;

    // Queue a command to load the section group with the specified properties.           
    sectionGroup.load("name,notebook/name"); 

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

            // Write the properties.
            console.log("Section group name: " + sectionGroup.name);
            console.log("Parent notebook name: " + sectionGroup.notebook.name);
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
OneNote.run(function (context) {

    // Get the section groups that are direct children of the current notebook.
    var sectionGroups = context.application.getActiveNotebook().sectionGroups;

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

    // Get the child section groups of the first section group in the notebook.
    var nestedSectionGroups = sectionGroups._GetItem(0).sectionGroups;

    // Queue a command to load the ID and name properties of the child section groups.
    nestedSectionGroups.load("id,name");

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

            // Write the properties for each child section group.
            $.each(nestedSectionGroups.items, function(index, sectionGroup) {
                console.log("Section group name: " + sectionGroup.name);  
                console.log("Section group ID: " + sectionGroup.id);  
            });
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
OneNote.run(function (context) {

    // Get the sections that are siblings of the current section.
    var sections = context.application.getActiveSection().parentSectionGroup.sections;

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

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

            // Write the properties for each section.
            $.each(sections.items, function(index, section) {
                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));
    }
});

toJSON()

toJSON(): OneNote.Interfaces.SectionGroupData;

Returns

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you are using this object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created.

track(): OneNote.SectionGroup;

Returns

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect.

untrack(): OneNote.SectionGroup;

Returns