Created
February 16, 2024 22:12
-
-
Save cddouglass/009e7f577aeb8afa057c411e3e8a3009 to your computer and use it in GitHub Desktop.
Gets, adds, and removes categories in the master list for the mailbox.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Work with the categories master list | |
description: 'Gets, adds, and removes categories in the master list for the mailbox.' | |
host: OUTLOOK | |
api_set: {} | |
script: | |
content: | | |
$("#get-master-categories").on("click", getMasterCategories); | |
$("#add-master-categories").on("click", addMasterCategories); | |
$("#remove-master-categories").on("click", removeMasterCategories); | |
function getMasterCategories() { | |
Office.context.mailbox.masterCategories.getAsync(function(asyncResult) { | |
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { | |
const categories = asyncResult.value; | |
if (categories && categories.length > 0) { | |
console.log("Master categories:"); | |
console.log(JSON.stringify(categories)); | |
} else { | |
console.log("There are no categories in the master list."); | |
} | |
} else { | |
console.error(asyncResult.error); | |
} | |
}); | |
} | |
function addMasterCategories() { | |
const masterCategoriesToAdd = [ | |
{ | |
displayName: "TestCategory", | |
color: Office.MailboxEnums.CategoryColor.Preset0 | |
} | |
]; | |
Office.context.mailbox.masterCategories.addAsync(masterCategoriesToAdd, function(asyncResult) { | |
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { | |
console.log("Successfully added categories to master list"); | |
} else { | |
console.log("masterCategories.addAsync call failed with error: " + asyncResult.error.message); | |
} | |
}); | |
} | |
function removeMasterCategories() { | |
const masterCategoriesToRemove = ["TestCategory"]; | |
Office.context.mailbox.masterCategories.removeAsync(masterCategoriesToRemove, function(asyncResult) { | |
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { | |
console.log("Successfully removed categories from master list"); | |
} else { | |
console.log("masterCategories.removeAsync call failed with error: " + asyncResult.error.message); | |
} | |
}); | |
} | |
language: typescript | |
template: | |
content: |- | |
<section class="ms-font-m"> | |
<p class="ms-font-m">This sample shows how to get, add, and remove <b>master categories</b> on the mailbox.</p> | |
</section> | |
<section class="samples ms-font-m"> | |
<h3>Try it out</h3> | |
<button id="add-master-categories" class="ms-Button"> | |
<span class="ms-Button-label">Add category to master list</span> | |
</button> | |
<button id="get-master-categories" class="ms-Button"> | |
<span class="ms-Button-label">Get categories master list</span> | |
</button> | |
<button id="remove-master-categories" class="ms-Button"> | |
<span class="ms-Button-label">Remove category from master list</span> | |
</button> | |
</section> | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
[email protected]/dist/css/fabric.min.css | |
[email protected]/dist/css/fabric.components.min.css | |
[email protected]/client/core.min.js | |
@types/core-js | |
[email protected] | |
@types/[email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment