I am trying to create an add-in for the outlook windows application. The following code should copy the email body to the clipboard, but it doesn't do that. I need to press the run button two times in order to get the content copied, but I need to copy the content from the first time! What is wrong with my code?
var messageBody = "";
export async function run() {
    Office.context.mailbox.item.body.getAsync(
        Office.CoercionType.Text,
        function (asyncResult) {
            if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
                messageBody = asyncResult.error;
            } else {
                messageBody = asyncResult.value;
            }
        });
    copyToClipboard(messageBody)
}
function copyToClipboard(text) {
    var copyhelper = document.createElement("input");
    copyhelper.className = 'copyhelper'
    document.body.appendChild(copyhelper);
    copyhelper.value = text;
    copyhelper.select();
    document.execCommand("copy");
    document.body.removeChild(copyhelper);
}
 
    