Office.CustomProperties interface

The CustomProperties object represents custom properties that are specific to a particular mail item and specific to an Outlook add-in. For example, there might be a need for an add-in to save some data that's specific to the current message that activated the add-in. If the user revisits the same message in the future and activates the add-in again, the add-in will be able to retrieve the data that had been saved as custom properties.

To learn more about CustomProperties, see Get and set add-in metadata for an Outlook add-in.

Remarks

[ API set: Mailbox 1.1 ]

When using custom properties in your add-in, keep in mind that:

  • Custom properties saved while in compose mode aren't transmitted to recipients of the mail item. When a message or appointment with custom properties is sent, its properties can be accessed from the item in the Sent Items folder. If you want to make custom data accessible to recipients, consider using InternetHeaders instead.

  • The maximum length of a CustomProperties JSON object is 2500 characters.

  • Outlook on Mac doesn't cache custom properties. If the user's network goes down, mail add-ins can't access their custom properties.

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

Methods

get(name)

Returns the value of the specified custom property.

getAll()

Returns an object with all custom properties in a collection of name/value pairs. The following are equivalent.

customProps.get("name")

var dictionary = customProps.getAll(); dictionary["name"]

You can iterate through the dictionary object to discover all names and values.

remove(name)

Removes the specified property from the custom property collection.

To make the removal of the property permanent, you must call the saveAsync method of the CustomProperties object.

saveAsync(callback, asyncContext)

Saves custom properties to a message or appointment.

You must call the saveAsync method to persist any changes made with the set method or the remove method of the CustomProperties object. The saving action is asynchronous.

It's a good practice to have your callback function check for and handle errors from saveAsync. In particular, a read add-in can be activated while the user is in a connected state in a read form, and subsequently the user becomes disconnected. If the add-in calls saveAsync while in the disconnected state, saveAsync would return an error. Your callback function should handle this error accordingly.

saveAsync(asyncContext)

Saves custom properties to a message or appointment.

You must call the saveAsync method to persist any changes made with the set method or the remove method of the CustomProperties object. The saving action is asynchronous.

It's a good practice to have your callback function check for and handle errors from saveAsync. In particular, a read add-in can be activated while the user is in a connected state in a read form, and subsequently the user becomes disconnected. If the add-in calls saveAsync while in the disconnected state, saveAsync would return an error. Your callback function should handle this error accordingly.

set(name, value)

Sets the specified property to the specified value.

The set method sets the specified property to the specified value. To ensure that the set property and value persist on the mail item, you must call the saveAsync method.

The set method creates a new property if the specified property doesn't already exist; otherwise, the existing value is replaced with the new value. The value parameter can be of any type; however, it's always passed to the server as a string.

Method Details

get(name)

Returns the value of the specified custom property.

get(name: string): any;

Parameters

name

string

The name of the custom property to be returned.

Returns

any

The value of the specified custom property.

Remarks

[ API set: Mailbox 1.1 ]

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml

const propertyName = $("#get-property-name").val();
const propertyValue = customProps.get(propertyName);
console.log(`The value of custom property "${propertyName}" is "${propertyValue}".`);

getAll()

Returns an object with all custom properties in a collection of name/value pairs. The following are equivalent.

customProps.get("name")

var dictionary = customProps.getAll(); dictionary["name"]

You can iterate through the dictionary object to discover all names and values.

getAll(): any;

Returns

any

An object with all custom properties in a collection of name/value pairs.

Remarks

[ API set: Mailbox 1.9 ]

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml

let allCustomProps;
if (Office.context.requirements.isSetSupported("Mailbox", "1.9")) {
  allCustomProps = customProps.getAll();
} else {
  allCustomProps = customProps["rawData"];
}

console.log(allCustomProps);

remove(name)

Removes the specified property from the custom property collection.

To make the removal of the property permanent, you must call the saveAsync method of the CustomProperties object.

remove(name: string): void;

Parameters

name

string

The name of the property to be removed.

Returns

void

Remarks

[ API set: Mailbox 1.1 ]

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

Important: The remove method isn't supported on a message that's currently loaded using the loadItemByIdAsync method. For more information, see Activate your Outlook add-in on multiple messages.

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml

const propertyName = $("#remove-property-name").val();
customProps.remove(propertyName);
console.log(`Custom property "${propertyName}" removed.`);

saveAsync(callback, asyncContext)

Saves custom properties to a message or appointment.

You must call the saveAsync method to persist any changes made with the set method or the remove method of the CustomProperties object. The saving action is asynchronous.

It's a good practice to have your callback function check for and handle errors from saveAsync. In particular, a read add-in can be activated while the user is in a connected state in a read form, and subsequently the user becomes disconnected. If the add-in calls saveAsync while in the disconnected state, saveAsync would return an error. Your callback function should handle this error accordingly.

saveAsync(callback: (asyncResult: Office.AsyncResult<void>) => void, asyncContext?: any): void;

Parameters

callback

(asyncResult: Office.AsyncResult<void>) => void

When the method completes, the function passed in the callback parameter is called with a single parameter of type Office.AsyncResult.

asyncContext

any

Optional. Any state data that is passed to the callback function.

Returns

void

Remarks

[ API set: Mailbox 1.1 ]

Important: In Outlook on Windows, custom properties saved while in compose mode only persist after the item being composed is closed or after Office.context.mailbox.item.saveAsync is called.

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml

customProps.saveAsync((result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.error(`saveAsync failed with message ${result.error.message}`);
    return;
  }

  console.log(`Custom properties saved with status: ${result.status}`);
});

saveAsync(asyncContext)

Saves custom properties to a message or appointment.

You must call the saveAsync method to persist any changes made with the set method or the remove method of the CustomProperties object. The saving action is asynchronous.

It's a good practice to have your callback function check for and handle errors from saveAsync. In particular, a read add-in can be activated while the user is in a connected state in a read form, and subsequently the user becomes disconnected. If the add-in calls saveAsync while in the disconnected state, saveAsync would return an error. Your callback function should handle this error accordingly.

saveAsync(asyncContext?: any): void;

Parameters

asyncContext

any

Optional. Any state data that is passed to the callback function.

Returns

void

Remarks

[ API set: Mailbox 1.1 ]

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

set(name, value)

Sets the specified property to the specified value.

The set method sets the specified property to the specified value. To ensure that the set property and value persist on the mail item, you must call the saveAsync method.

The set method creates a new property if the specified property doesn't already exist; otherwise, the existing value is replaced with the new value. The value parameter can be of any type; however, it's always passed to the server as a string.

set(name: string, value: string): void;

Parameters

name

string

The name of the property to be set.

value

string

The value of the property to be set.

Returns

void

Remarks

[ API set: Mailbox 1.1 ]

Minimum permission level: read item

Applicable Outlook mode: Compose or Read

Important: The set method isn't supported on a message that's currently loaded using the loadItemByIdAsync method. For more information, see Activate your Outlook add-in on multiple messages.

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/15-item-custom-properties/load-set-get-save.yaml

const propertyName = $("#set-property-name").val();
const propertyValue = $("#property-value").val();
customProps.set(propertyName, propertyValue);
console.log(`Custom property "${propertyName}" set to value "${propertyValue}".`);