-2

I am trying to get message body and write it in a div as text. But it doesn't work.. What is wrong?

The following is the part of my code..`

$('#btn1').click(yaz);

......

function yaz() {
    $('.result').text(denemefonk);
  }

  function denemefonk() {
    Office.context.mailbox.body.getAsync(Office.CoercionType.Text);
  }
  • Try to narrow down the problem. Is it with getting the message body, or with putting it in a div? Get the message body and log it to the console to see if that works. Put some static text into the div to see if that works. When you have both pieces working, put them together. – Roland Weber Oct 25 '18 at 07:39

2 Answers2

2

The function getAsync has asynchronous nature, so you need to wait for callback. The code may look like the following ...

var body = Office.context.mailbox.item.body;
// Get the body asynchronous as text
body.getAsync(Office.CoercionType.Text, function (asyncResult) {
   if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
       // do something with the error
   } else {
       $('.result').html(asyncResult.value);
   }
});

I also notice you call the function Office.context.mailbox.body.getAsync. There is no body object in mailbox, this object belongs to a particular item, see my example. Please pay attention to documentation on Office.js API.

Slava Ivanov
  • 6,666
  • 2
  • 23
  • 34
  • Yes, sir. You are right. Yesterday, before you write this message I noticed and did it. It works fine now. Thank you. – canciftcioglu Oct 26 '18 at 06:11
  • Hello @Slava, If my add-in task pane is opened and i change something in my appointment meeting fields then task pane data is not refreshing untill i reopen the task pane. Please answer of this question https://stackoverflow.com/questions/72256645/how-to-change-refresh-appointment-organizer-data-to-add-ins-task-pane – Vikas Rajput May 17 '22 at 06:17
0

It should be like this:

$('#btn1').click(yaz());

And this:

$('.result').text(denemefonk());

Because you want to call the functions.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79