Skip to content

Instantly share code, notes, and snippets.

@JuaneloJuanelo
Created March 1, 2023 16:09
Show Gist options
  • Save JuaneloJuanelo/e8c6823b2b241ed42fdd3a33ff66f2bc to your computer and use it in GitHub Desktop.
Save JuaneloJuanelo/e8c6823b2b241ed42fdd3a33ff66f2bc to your computer and use it in GitHub Desktop.
Prepends and Multiselect Samples
name: Multiselect
description: Prepends and Multiselect Samples
host: OUTLOOK
api_set: {}
script:
content: |
$("#prepend-on-send").click(prependOnSend);
$("#multiSelect").click(multiselect);
function prependOnSend() {
// This snippet prepends text to the beginning of the message or appointment's body once it's sent.
const text = $("#text-field").val();
// It's recommended to call getTypeAsync and pass its returned value to the options.coercionType parameter of the prependOnSendAsync call.
Office.context.mailbox.item.body.getTypeAsync((asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log("Action failed with error: " + asyncResult.error.message);
return;
}
const bodyFormat = asyncResult.value;
Office.context.mailbox.item.body.prependOnSendAsync(text, { coercionType: bodyFormat }, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log("Action failed with error: " + asyncResult.error.message);
return;
}
console.log(
`"${text}" will be prepended to the body once the message or appointment is sent. Send the mail item to test this feature.`
);
});
});
}
function multiselect() {
Office.context.mailbox.getSelectedItemsAsync(function(result) {
console.log(result.value);
});
}
language: typescript
template:
content: "<section class=\"ms-font-m\">\n\t<p class=\"ms-font-m\">This sample prepends text to the beginning of the message or appointment's body once it's sent.\n\t</p>\n\t<p><b>Required mode</b>: Compose</p>\n</section>\n\n<section class=\"samples ms-font-m\">\n\t<h3>Try it out</h3>\n\t<p><b>Important</b>: To use <code>prependOnSendAsync</code>, you must set <code>AppendOnSend</code> as an extended\n\t\tpermission in the <code>ExtendedPermissions</code> manifest element. <code>appendOnSendAsync</code> and\n\t\t<code>prependOnSendAsync</code> both use the <code>AppendOnSend</code> extended permission. To learn more about\n\t\tprepend-on-send, see <a href=\"https://learn.microsoft.com/office/dev/add-ins/outlook/append-on-send\"\n\t\t\ttarget=\"_blank\">Prepend or append content to a message or appointment body on send</a>.</p>\n\t<div class=\"ms-TextField\">\n\t\t<label class=\"ms-Label\">Enter text to prepend to the body: </label>\n\t\t<input id=\"text-field\" type=\"text\" class=\"ms-TextField-field\" value=\"P.S. This text was prepended on send.\">\n </div>\n\t\t<br>\n\t\t<button id=\"prepend-on-send\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Prepend text on send</span>\n </button>\n\n\t\t<button id=\"multiSelect\" class=\"ms-Button\">\n\t\t <span class=\"ms-Button-label\">Multiselect items</span>\n\t\t </button>\n</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/beta/hosted/office.js
@types/office-js-preview
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
core-js@2.4.1/client/core.min.js
@types/core-js
jquery@3.1.1
@types/jquery@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment