TypeError: Cannot read properties of undefined (reading ‘__type’)

We Are Going To Discuss About TypeError: Cannot read properties of undefined (reading ‘__type’). So lets Start this Angular Article.

TypeError: Cannot read properties of undefined (reading ‘__type’)

How to solve TypeError: Cannot read properties of undefined (reading ‘__type’)

Try to use the following code:
var options = { asyncContext: { type: attachment.attachmentType } }; item.getAttachmentContentAsync(attachment.id, options, function (result) { if (result.status == Office.AsyncResultStatus.Succeeded) { //console.log("Call returned success!"); var AttachmentContent = result.value; // Get the attachment content if (AttachmentContent.format == Office.MailboxEnums.AttachmentContentFormat.Base64) { // handle file attachment //console.log(attachment.name + " Base64 String: " + AttachmentContent.content); console.log("Downloaded " + attachment.name); fnCallback(AttachmentContent.content); } else if (result.format == Office.MailboxEnums.AttachmentContentFormat.Eml) { // handle item attachment } else { // handle cloud attachment } } else { var err = result.error; console.log("Download failed: " + err.name + ": " + err.message); } });

TypeError: Cannot read properties of undefined (reading ‘__type’)

Try to use the following code:
var options = { asyncContext: { type: attachment.attachmentType } }; item.getAttachmentContentAsync(attachment.id, options, function (result) { if (result.status == Office.AsyncResultStatus.Succeeded) { //console.log("Call returned success!"); var AttachmentContent = result.value; // Get the attachment content if (AttachmentContent.format == Office.MailboxEnums.AttachmentContentFormat.Base64) { // handle file attachment //console.log(attachment.name + " Base64 String: " + AttachmentContent.content); console.log("Downloaded " + attachment.name); fnCallback(AttachmentContent.content); } else if (result.format == Office.MailboxEnums.AttachmentContentFormat.Eml) { // handle item attachment } else { // handle cloud attachment } } else { var err = result.error; console.log("Download failed: " + err.name + ": " + err.message); } });

Solution 1

Try to use the following code:

var options = { asyncContext: { type: attachment.attachmentType } };
item.getAttachmentContentAsync(attachment.id, options, function (result) 
{
    if (result.status == Office.AsyncResultStatus.Succeeded) 
    {
        //console.log("Call returned success!");
        var AttachmentContent = result.value; // Get the attachment content
        if (AttachmentContent.format == Office.MailboxEnums.AttachmentContentFormat.Base64) 
        {
            // handle file attachment
            //console.log(attachment.name + " Base64 String: " + AttachmentContent.content);
            console.log("Downloaded " + attachment.name);
            fnCallback(AttachmentContent.content);
        }
        else if (result.format == Office.MailboxEnums.AttachmentContentFormat.Eml) {
            // handle item attachment
        }
        else {
            // handle cloud attachment  
        }
    }
    else 
    {
        var err = result.error;
        console.log("Download failed: " + err.name + ": " + err.message);
    }
});

Original Author Eugene Astafiev Of This Content

Solution 2

Could you please try the following code snippet below? With Cloud attachment we are not getting any error with this.

// method to get the attachment content
function getContentById(id)
{
  if (id)
  {
    console.log("Getting content for attachment with id: " + id);
    Office.context.mailbox.item.getAttachmentContentAsync
    (
      id,
      function (asyncResult)
      {
        console.log(JSON.stringify(asyncResult));
      }
    );
  }
  else
  {
    console.log("item does not have attachment " + index);
  }
}

var index = 0; // 0 based index of the attachment you want to get content for.
if (Office.context.mailbox.item.attachments)
{
  var id;
  // read
  if (Office.context.mailbox.item.attachments.length > index)
  {
    id = Office.context.mailbox.item.attachments[index].id;
  }
  getContentById(id);
}
else
{
  // compose
  Office.context.mailbox.item.getAttachmentsAsync
  (
    function (asyncResult)
    {
      var id;
      if (asyncResult.status === "succeeded")
      {
        var attachments = asyncResult.value;
        if (attachments.length > index)
        {
          id = attachments[index].id;
        }
      }
      console.log("getAttachmentsAsync result: " + JSON.stringify(asyncResult));
      getContentById(id);
    }
  );
}

Original Author Outlook Add-ins Team – MSFT Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment