Word.SensitivityLabelsCatalog class
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Provides methods to check the status of the catalog of sensitivity labels in Word and retrieve all available sensitivity labels if the catalog is enabled.
- Extends
Properties
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| get |
Gets the labeling capabilities of the sensitivity label catalog in Word. |
| get |
Gets the labeling capability status of the sensitivity label catalog in Word. |
Methods
| get |
Gets the attribute-based access control (ABAC) attributes available for sensitivity labels. |
| get |
Gets all the sensitivity labels that are enabled in Word. |
| 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 |
| new |
Create a new instance of the |
| toJSON() | Overrides the JavaScript |
| 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 |
| 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 |
Property Details
context
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
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
getLabelingCapabilities
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Gets the labeling capabilities of the sensitivity label catalog in Word.
readonly getLabelingCapabilities: Word.LabelingCapability[];
Property Value
Remarks
getLabelingCapability
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Gets the labeling capability status of the sensitivity label catalog in Word.
readonly getLabelingCapability: Word.LabelingCapability | "NoLicense" | "LabelingDisabled" | "LabelingPolicyNotFound" | "LabelingEnabled" | "AttributeBasedAccessControlEnabled";
Property Value
Word.LabelingCapability | "NoLicense" | "LabelingDisabled" | "LabelingPolicyNotFound" | "LabelingEnabled" | "AttributeBasedAccessControlEnabled"
Remarks
API set: WordApi BETA (PREVIEW ONLY)
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/99-preview-apis/manage-sensitivity-labels.yaml
// Check whether sensitivity labeling is available for the current user.
await Word.run(async (context) => {
const labelCatalog: Word.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
if (!labelCatalog) {
console.warn("The sensitivity label catalog isn't available.");
return;
}
labelCatalog.load("getLabelingCapability");
await context.sync();
switch (labelCatalog.getLabelingCapability) {
case Word.LabelingCapability.labelingEnabled:
console.log("Sensitivity labeling is enabled.");
break;
case Word.LabelingCapability.labelingDisabled:
console.log("Sensitivity labeling is disabled.");
break;
case Word.LabelingCapability.labelingPolicyNotFound:
console.log("No sensitivity labeling policy was found.");
break;
case Word.LabelingCapability.noLicense:
console.log("The current user doesn't have a valid sensitivity labeling license.");
break;
default:
console.log(`Unknown labeling capability: ${labelCatalog.getLabelingCapability}`);
break;
}
});
Method Details
getAttributes()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Gets the attribute-based access control (ABAC) attributes available for sensitivity labels.
getAttributes(): OfficeExtension.ClientResult<Word.SensitivityLabelAbacAttribute[]>;
Returns
Remarks
API set: WordApi BETA (PREVIEW ONLY)
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/99-preview-apis/manage-sensitivity-labels.yaml
// Get available ABAC attributes and describe the kind of value each attribute accepts.
const container = document.getElementById("abac-attributes");
while (container.firstChild) {
container.removeChild(container.firstChild);
}
await Word.run(async (context) => {
const labelCatalog: Word.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
if (!labelCatalog) {
console.warn("The sensitivity label catalog isn't available.");
return;
}
labelCatalog.load("getLabelingCapabilities");
await context.sync();
const capabilities: Word.LabelingCapability[] = labelCatalog.getLabelingCapabilities;
if (capabilities.indexOf(Word.LabelingCapability.attributeBasedAccessControlEnabled) === -1) {
console.warn("ABAC attributes aren't enabled or available for the current user.");
return;
}
const catalogAttributes: OfficeExtension.ClientResult<Word.SensitivityLabelAbacAttribute[]> =
labelCatalog.getAttributes();
await context.sync();
if (catalogAttributes.value.length === 0) {
console.log("No ABAC attributes are available in the sensitivity label catalog.");
return;
}
console.log("Available ABAC attributes:");
catalogAttributes.value.forEach((attribute: Word.SensitivityLabelAbacAttribute) => {
let dataTypeDescription: string;
switch (attribute.dataType) {
case Word.SensitivityLabelAbacAttributeDataType.booleanValue:
dataTypeDescription = "Boolean";
break;
case Word.SensitivityLabelAbacAttributeDataType.dateValue:
dataTypeDescription = "Date";
break;
case Word.SensitivityLabelAbacAttributeDataType.numberValue:
dataTypeDescription = "Number";
break;
case Word.SensitivityLabelAbacAttributeDataType.stringValue:
dataTypeDescription = "String";
break;
case Word.SensitivityLabelAbacAttributeDataType.unknown:
dataTypeDescription = "Unknown";
break;
default:
dataTypeDescription = `Unrecognized (${attribute.dataType})`;
break;
}
console.log(`ABAC attribute: ${attribute.displayName}`, {
dataType: attribute.dataType,
dataTypeDescription,
displayOrder: attribute.displayOrder,
isActive: attribute.isActive,
isMultiValued: attribute.isMultiValued,
values: attribute.values.map((attributeValue: Word.SensitivityLabelAbacAttributeValue) => ({
displayName: attributeValue.displayName,
displayOrder: attributeValue.displayOrder,
id: attributeValue.id,
isActive: attributeValue.isActive
}))
});
});
addAttributeOptions(catalogAttributes.value);
});
getLabels()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Gets all the sensitivity labels that are enabled in Word.
getLabels(): Word.SensitivityLabelDetailsCollection;
Returns
Remarks
API set: WordApi BETA (PREVIEW ONLY)
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/99-preview-apis/manage-sensitivity-labels.yaml
await Word.run(async (context) => {
const labelSelect = document.getElementById("label-id") as HTMLSelectElement;
labelSelect.options.length = 0;
const placeholder = document.createElement("option");
placeholder.textContent = "Select a label";
placeholder.value = "";
labelSelect.add(placeholder);
// Get the sensitivity labels that the organization published for the current user.
const labelCatalog: Word.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
if (!labelCatalog) {
console.warn("The sensitivity label catalog isn't available.");
return;
}
const availableLabels: Word.SensitivityLabelDetailsCollection = labelCatalog.getLabels();
// Load the properties for every label in the catalog.
availableLabels.load(
"items/color,items/id,items/isAbacAttributesRequired,items/isAbacEnabled,items/isEnabled," +
"items/name,items/order,items/protectionType,items/siteId,items/tooltip," +
"items/children/items/id,items/children/items/name,items/children/items/isEnabled"
);
await context.sync();
if (availableLabels.items.length === 0) {
console.log("No sensitivity labels are available for the current user.");
return;
}
// Display the loaded properties for each available label.
console.log("Available sensitivity labels:");
availableLabels.items.forEach((labelDetails: Word.SensitivityLabelDetails) => {
const childLabels = labelDetails.children && labelDetails.children.items.length
? labelDetails.children.items
.map((childLabel: Word.SensitivityLabelDetails) => `${childLabel.name} (${childLabel.id})`)
.join(", ")
: "None";
console.log(
`\n${labelDetails.name}\n` +
` ID: ${labelDetails.id}\n` +
` Site ID: ${labelDetails.siteId}\n` +
` Tooltip: ${labelDetails.tooltip}\n` +
` Color: ${labelDetails.color}\n` +
` Enabled: ${labelDetails.isEnabled ? "Yes" : "No"}\n` +
` Display order: ${labelDetails.order}\n` +
` ABAC enabled: ${labelDetails.isAbacEnabled ? "Yes" : "No"}\n` +
` ABAC attributes required: ${labelDetails.isAbacAttributesRequired ? "Yes" : "No"}\n` +
` Sublabels: ${childLabels}\n` +
` Protection type: ${labelDetails.protectionType}`
);
});
addLabelOptions(availableLabels);
});
load(options)
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(options?: Word.Interfaces.SensitivityLabelsCatalogLoadOptions): Word.SensitivityLabelsCatalog;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
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[]): Word.SensitivityLabelsCatalog;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
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;
}): Word.SensitivityLabelsCatalog;
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
newObject(context)
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Create a new instance of the Word.SensitivityLabelsCatalog object.
static newObject(context: OfficeExtension.ClientRequestContext): Word.SensitivityLabelsCatalog;
Parameters
Returns
toJSON()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
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 Word.SensitivityLabelsCatalog object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.SensitivityLabelsCatalogData) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Word.Interfaces.SensitivityLabelsCatalogData;
Returns
track()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
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. If this object is part of a collection, you should also track the parent collection.
track(): Word.SensitivityLabelsCatalog;
Returns
untrack()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
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(): Word.SensitivityLabelsCatalog;