OneNote.SectionGroup class
Represents a OneNote section group. Section groups can contain sections and other section groups.
- Extends
Remarks
Properties
client |
The client url of the section group. Read only |
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. Read-only. |
name | Gets the name of the section group. Read-only. |
notebook | Gets the notebook that contains the section group. Read-only. |
parent |
Gets the section group that contains the section group. Throws ItemNotFound if the section group is a direct child of the notebook. Read-only. |
parent |
Gets the section group that contains the section group. Returns null if the section group is a direct child of the notebook. Read-only. |
section |
The collection of section groups in the section group. Read only |
sections | The collection of sections in the section group. Read only |
Methods
add |
Adds a new section to the end of the section group. |
add |
Adds a new section group to the end of this sectionGroup. |
get |
Gets the REST API ID. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
toJSON() | Overrides the JavaScript |
track() | Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for |
untrack() | Release the memory associated with this object, if it has previously been tracked. This call is shorthand for |
Property Details
clientUrl
The client url of the section group. Read only
readonly clientUrl: string;
Property Value
string
Remarks
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. Read-only.
readonly id: string;
Property Value
string
Remarks
name
Gets the name of the section group. Read-only.
readonly name: string;
Property Value
string
Remarks
notebook
Gets the notebook that contains the section group. Read-only.
readonly notebook: OneNote.Notebook;
Property Value
Remarks
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.
readonly parentSectionGroup: OneNote.SectionGroup;
Property Value
Remarks
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.
readonly parentSectionGroupOrNull: OneNote.SectionGroup;
Property Value
Remarks
sectionGroups
The collection of section groups in the section group. Read only
readonly sectionGroups: OneNote.SectionGroupCollection;
Property Value
Remarks
sections
The collection of sections in the section group. Read only
readonly sections: OneNote.SectionCollection;
Property Value
Remarks
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
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
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
OfficeExtension.ClientResult<string>
Remarks
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
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 is 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 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
Office Add-ins