Get Email body and set it as To Do Task content

This commit is contained in:
luismanez 2020-09-28 14:51:38 +02:00
parent e43f35704a
commit 0fbe0d1edc
3 changed files with 12 additions and 9 deletions

View File

@ -20,12 +20,17 @@ export interface ICreateTaskWebPartProps {
export default class CreateTaskWebPart extends BaseClientSideWebPart<ICreateTaskWebPartProps> { export default class CreateTaskWebPart extends BaseClientSideWebPart<ICreateTaskWebPartProps> {
private _graphHttpClient: MSGraphClient; private _graphHttpClient: MSGraphClient;
private _mailBody: string;
protected onInit(): Promise<void> { protected onInit(): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.context.msGraphClientFactory.getClient().then(client => { this.context.msGraphClientFactory.getClient().then(client => {
this._graphHttpClient = client; this._graphHttpClient = client;
resolve(); const mailboxItem: Office.MessageRead = this.context.sdks.office.context.mailbox.item;
mailboxItem.body.getAsync(Office.CoercionType.Text, (asyncResult: Office.AsyncResult<string>) => {
this._mailBody = asyncResult.value;
resolve();
});
}).catch(error => { }).catch(error => {
console.log(error); console.log(error);
reject(error); reject(error);
@ -43,7 +48,8 @@ export default class CreateTaskWebPart extends BaseClientSideWebPart<ICreateTask
id: mailboxItem.itemId, id: mailboxItem.itemId,
subject: mailboxItem.subject, subject: mailboxItem.subject,
from: mailboxItem.from.emailAddress, from: mailboxItem.from.emailAddress,
to: mailboxItem.to[0].emailAddress to: mailboxItem.to[0].emailAddress,
body: this._mailBody
} }
}; };
return context; return context;

View File

@ -17,8 +17,6 @@ import {
MessageBarType MessageBarType
} from "office-ui-fabric-react"; } from "office-ui-fabric-react";
import { MSGraphClient } from "@microsoft/sp-http";
export default class CreateTask extends React.Component< export default class CreateTask extends React.Component<
ICreateTaskProps, ICreateTaskProps,
ICreateTaskState ICreateTaskState
@ -30,10 +28,8 @@ export default class CreateTask extends React.Component<
listItemAdded: false, listItemAdded: false,
selectedList: undefined, selectedList: undefined,
todoLists: [], todoLists: [],
newTaskTitle: this.props.context.item newTaskTitle: this.props.context.item ? this.props.context.item.subject : "New Task title here!",
? this.props.context.item.subject showSelectListError: false
: "New Task title here!",
showSelectListError: false
}; };
this._onDropdownChange = this._onDropdownChange.bind(this); this._onDropdownChange = this._onDropdownChange.bind(this);
@ -166,7 +162,7 @@ export default class CreateTask extends React.Component<
status: "notStarted", status: "notStarted",
title: taskTitle, title: taskTitle,
body: { body: {
content: "You have a new task to do added from SPFx component!", content: this.props.context.item.body,
contentType: "text", contentType: "text",
}, },
}; };

View File

@ -3,4 +3,5 @@ export interface IMailItem {
subject: string; subject: string;
from: string; from: string;
to: string; to: string;
body: string;
} }