OneNote.SectionGroup class

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

Extends

Remarks

[ API set: OneNoteApi 1.1 ]

Properties

clientUrl

The client URL of the section group.

context

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

id

Gets the ID of the section group.

name

Gets the name of the section group.

notebook

Gets the notebook that contains the section group.

parentSectionGroup

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

parentSectionGroupOrNull

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

sectionGroups

The collection of section groups in the section group.

sections

The collection of sections in the section group.

Methods

addSection(title)

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

addSectionGroup(name)

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

getRestApiId()

Gets the REST API ID.

load(options)

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.

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's passed to it.) Whereas the original OneNote.SectionGroup object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.SectionGroupData) that contains shallow copies of any loaded child properties from the original object.

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're 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 need to add 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'll need to call context.sync() before the memory release takes effect.

Property Details

clientUrl

The client URL of the section group.

readonly clientUrl: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

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

id

Gets the ID of the section group.

readonly id: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

name

Gets the name of the section group.

readonly name: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

notebook

Gets the notebook that contains the section group.

readonly notebook: OneNote.Notebook;

Property Value

Remarks

[ 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.

readonly parentSectionGroup: OneNote.SectionGroup;

Property Value

Remarks

[ 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.

readonly parentSectionGroupOrNull: OneNote.SectionGroup;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

sectionGroups

The collection of section groups in the section group.

readonly sectionGroups: OneNote.SectionGroupCollection;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

sections

The collection of sections in the section group.

readonly sections: OneNote.SectionCollection;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

Method Details

addSection(title)

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

addSection(title: string): OneNote.Section;

Parameters

title

string

The name of the new section.

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {

    // Get the section groups that are direct children of the current notebook.
    const 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.
    await context.sync();
            
    // Add a section to each section group.
    $.each(sectionGroups.items, function(index, sectionGroup) {
        sectionGroup.addSection("Agenda");
    });
    
    // Run the queued commands.
    await context.sync();
});

addSectionGroup(name)

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

addSectionGroup(name: string): OneNote.SectionGroup;

Parameters

name

string

The name of the new section.

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {
    let sectionGroup;
    let nestedSectionGroup;

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

    // Queue a command to add a new section group.
    const 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.
    await context.sync();

    sectionGroup = sectionGroups.items[0];
    sectionGroup.load();
    await context.sync();

    nestedSectionGroup = sectionGroup.addSectionGroup("Sample nested section group");
    nestedSectionGroup.load();
    await context.sync();
    
    console.log("New nested section group name is " + nestedSectionGroup.name);
});

getRestApiId()

Gets the REST API ID.

getRestApiId(): OfficeExtension.ClientResult<string>;

Returns

Remarks

[ API set: OneNoteApi 1.1 ]

load(options)

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

load(options?: OneNote.Interfaces.SectionGroupLoadOptions): OneNote.SectionGroup;

Parameters

options
OneNote.Interfaces.SectionGroupLoadOptions

Provides options for which properties of the object to load.

Returns

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.SectionGroup;

Parameters

propertyNames

string | string[]

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

Returns

Examples

await OneNote.run(async (context) => {
        
    // Get the parent section group that contains the current section.
    const 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.
    await context.sync();
            
    // Write the properties.
    console.log("Section group name: " + sectionGroup.name);
    console.log("Section group ID: " + sectionGroup.id);
});

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.SectionGroup;

Parameters

propertyNamesAndPaths

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

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

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's passed to it.) Whereas the original OneNote.SectionGroup object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.SectionGroupData) that contains shallow copies of any loaded child properties from the original object.

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're 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 need to add 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'll need to call context.sync() before the memory release takes effect.

untrack(): OneNote.SectionGroup;

Returns