id: outlook-item-custom-properties-load-set-get-save name: Work with item custom properties description: Gets the custom properties that the add-in placed on the current item, sets a new one, gets it, removes it, and saves all custom properties back to the item. host: OUTLOOK api_set: Mailbox: '1.1' script: content: |- let customProps; document.getElementById("load").addEventListener("click", load); document.getElementById("get").addEventListener("click", get); document.getElementById("get-all").addEventListener("click", getAll); document.getElementById("set").addEventListener("click", set); document.getElementById("remove").addEventListener("click", remove); document.getElementById("save").addEventListener("click", save); function load() { Office.context.mailbox.item.loadCustomPropertiesAsync((result) => { if (result.status === Office.AsyncResultStatus.Failed) { console.error(`loadCustomPropertiesAsync failed with message ${result.error.message}`); return; } customProps = result.value; console.log("Loaded the CustomProperties object."); }); } function get() { const propertyName = (document.getElementById("get-property-name") as HTMLInputElement).value; const propertyValue = customProps.get(propertyName); console.log(`The value of custom property "${propertyName}" is "${propertyValue}".`); } function getAll() { let allCustomProps; if (Office.context.requirements.isSetSupported("Mailbox", "1.9")) { allCustomProps = customProps.getAll(); } else { allCustomProps = customProps["rawData"]; } console.log(allCustomProps); } function set() { const propertyName = (document.getElementById("set-property-name") as HTMLInputElement).value; const propertyValue = (document.getElementById("property-value") as HTMLInputElement).value; customProps.set(propertyName, propertyValue); console.log(`Custom property "${propertyName}" set to value "${propertyValue}".`); } function remove() { const propertyName = (document.getElementById("remove-property-name") as HTMLInputElement).value; customProps.remove(propertyName); console.log(`Custom property "${propertyName}" removed.`); } function save() { 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}`); }); } language: typescript template: content: |-

This sample shows how to set, save, and get the custom per-item properties of an add-in.

Try it out

First load the CustomProperties object of the mail item.

language: html style: content: |- body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 14px; line-height: 1.5; padding: 10px; } section { margin-bottom: 20px; } h3 { margin-top: 0; margin-bottom: 10px; font-size: 16px; } p { margin: 0 0 10px 0; } button { background-color: #f0f0f0; color: #333333; border: 1px solid #8a8a8a; padding: 8px 16px; font-size: 14px; cursor: pointer; border-radius: 2px; margin-left: 20px; margin-bottom: 5px; min-width: 80px; display: block; } button:hover { background-color: #e0e0e0; } button:active { background-color: #d0d0d0; } input { padding: 8px; margin: 5px 0; border: 1px solid #ccc; border-radius: 2px; font-size: 14px; } .header { text-align: center; background-color: #f3f2f1; padding: 10px; } language: css libraries: |- https://appsforoffice.microsoft.com/lib/1/hosted/office.js https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/office-js/index.d.ts