Edit

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

getLabelingCapabilities

Gets the labeling capabilities for Excel. Use Array.includes to determine whether a capability is available.

getLabelingCapability

Gets whether the catalog of sensitivity labels is enabled in Excel.

Methods

getAttributes()

Gets the attribute-based access control (ABAC) attribute catalog metadata for ABAC-enabled labels. Verify the host's labeling capabilities include attributeBasedAccessControlEnabled; otherwise this method fails with an error.

getLabels()

Gets sensitivity labels that are available to the current user.

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 Excel.SensitivityLabelsCatalog object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.SensitivityLabelsCatalogData) that contains shallow copies of any loaded child properties from the original object.

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 for Excel. Use Array.includes to determine whether a capability is available.

readonly getLabelingCapabilities: Excel.LabelingCapability[];

Property Value

Remarks

API set: ExcelApi BETA (PREVIEW ONLY)

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 whether the catalog of sensitivity labels is enabled in Excel.

readonly getLabelingCapability: Excel.LabelingCapability | "NoLicense" | "LabelingDisabled" | "LabelingPolicyNotFound" | "LabelingEnabled" | "AttributeBasedAccessControlEnabled";

Property Value

Excel.LabelingCapability | "NoLicense" | "LabelingDisabled" | "LabelingPolicyNotFound" | "LabelingEnabled" | "AttributeBasedAccessControlEnabled"

Remarks

API set: ExcelApi BETA (PREVIEW ONLY)

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/98-preview-apis/manage-sensitivity-labels.yaml

// Check whether sensitivity labeling is available for the current user.
await Excel.run(async (context) => {
    const labelCatalog: Excel.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
    if (!labelCatalog) {
        console.warn("The sensitivity label catalog isn't available in this version of Excel.");
        return;
    }

    labelCatalog.load("getLabelingCapability");
    await context.sync();

    switch (labelCatalog.getLabelingCapability) {
        case Excel.LabelingCapability.labelingEnabled:
            console.log("Sensitivity labeling is enabled.");
            break;
        case Excel.LabelingCapability.labelingDisabled:
            console.log("Sensitivity labeling is disabled.");
            break;
        case Excel.LabelingCapability.labelingPolicyNotFound:
            console.log("No sensitivity labeling policy was found.");
            break;
        case Excel.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) attribute catalog metadata for ABAC-enabled labels. Verify the host's labeling capabilities include attributeBasedAccessControlEnabled; otherwise this method fails with an error.

getAttributes(): OfficeExtension.ClientResult<SensitivityLabelAbacAttribute[]>;

Returns

The available ABAC attributes for the current user.

Remarks

API set: ExcelApi BETA (PREVIEW ONLY)

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/98-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 Excel.run(async (context) => {
    const labelCatalog: Excel.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
    if (!labelCatalog) {
        console.warn("The sensitivity label catalog isn't available in this version of Excel.");
        return;
    }

    labelCatalog.load("getLabelingCapabilities");
    await context.sync();

    const capabilities: Excel.LabelingCapability[] = labelCatalog.getLabelingCapabilities;
    if (capabilities.indexOf(Excel.LabelingCapability.attributeBasedAccessControlEnabled) === -1) {
        console.warn("ABAC attributes aren't enabled or available for the current user.");
        return;
    }

    const catalogAttributes: OfficeExtension.ClientResult<Excel.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: Excel.SensitivityLabelAbacAttribute) => {
        let dataTypeDescription: string;
        switch (attribute.dataType) {
            case Excel.SensitivityLabelAbacAttributeDataType.booleanValue:
                dataTypeDescription = "Boolean";
                break;
            case Excel.SensitivityLabelAbacAttributeDataType.dateValue:
                dataTypeDescription = "Date";
                break;
            case Excel.SensitivityLabelAbacAttributeDataType.numberValue:
                dataTypeDescription = "Number";
                break;
            case Excel.SensitivityLabelAbacAttributeDataType.stringValue:
                dataTypeDescription = "String";
                break;
            case Excel.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: Excel.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 sensitivity labels that are available to the current user.

getLabels(): Excel.SensitivityLabelDetailsCollection;

Returns

The current SensitivityLabelDetailsCollection object.

Remarks

API set: ExcelApi BETA (PREVIEW ONLY)

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/98-preview-apis/manage-sensitivity-labels.yaml

// Get the published labels and sublabels available to the current user.
await Excel.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);

    const labelCatalog: Excel.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
    if (!labelCatalog) {
        console.warn("The sensitivity label catalog isn't available in this version of Excel.");
        return;
    }

    const availableLabels: Excel.SensitivityLabelDetailsCollection = labelCatalog.getLabels();
    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;
    }

    console.log("Available sensitivity labels:");
    availableLabels.items.forEach((labelDetails: Excel.SensitivityLabelDetails) => {
        const childLabels = labelDetails.children && labelDetails.children.items.length
            ? labelDetails.children.items
                .map((childLabel: Excel.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?: Excel.Interfaces.SensitivityLabelsCatalogLoadOptions): Excel.SensitivityLabelsCatalog;

Parameters

options
Excel.Interfaces.SensitivityLabelsCatalogLoadOptions

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[]): Excel.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;
        }): Excel.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

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 Excel.SensitivityLabelsCatalog object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.SensitivityLabelsCatalogData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.SensitivityLabelsCatalogData;

Returns