创建全天活动失败 [英] Creating All Day Event failing

查看:99
本文介绍了创建全天活动失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个全天活动:

I'm trying to create an All Day event:

let foobar: any = {
    "subject": calendarEvent.Title+"v5",
    "body": {
        "contentType": "HTML",
        "content": calendarEvent! || !calendarEvent.Description ? "No Description": calendarEvent.Description,
    },
    "start": {
        "dateTime": calendarEvent.EventDate,
        "timeZone": moment.tz.guess(),
    },
    "end": {
        "dateTime": calendarEvent.EndDate,
        "timeZone": moment.tz.guess(),
    },
    "location": {
        "displayName": !calendarEvent || !calendarEvent.Location ? "No Location": calendarEvent.Location,
    },
    "isAllDay": !calendarEvent || !calendarEvent.fAllDayEvent ? false : true,
};

context.msGraphClientFactory.getClient()
    .then((client: MSGraphClient) => {
        client.api("/me/calendar/events").post(foobar)
        .then((content: any) => {
            console.log("CalendarService | createCalendarEvent | content: ", content);
        });
    });

日志:

当我包含"isAllDay"属性时,它失败并显示400(错误请求).

When I include the `isAllDay" property, it fails with a 400 (Bad Request).

我排除了该属性,并且正在创建没有问题的事件.

I exclude the property, and it's creating the event w/out issue.

有什么建议吗?

编辑:忘了提及,如果我将isAllDay作为false传递,则会创建该事件.

forgot to mention, if I pass isAllDay as false, the event is created.

EDIT2 :这是通过SPFx项目中的MSGraphClient连接的.

This is connecting through the MSGraphClient from an SPFx project.

推荐答案

在创建全天"事件时,startend时间应仅指定日期,而不是日期和时间(或更准确地说,时间应为00:00:00):

When creating an "All Day" event, you start and end times should only specify the date, not the date and time (or more accurately, the time should be 00:00:00):

let foobar: any = {
    "subject": calendarEvent.Title+"v5",
    "body": {
        "contentType": "HTML",
        "content": calendarEvent! || !calendarEvent.Description ? "No Description": calendarEvent.Description,
    },
    "start": {
        "dateTime": !calendarEvent.fAllDayEvent ? calendarEvent.EventDate : calendarEvent.EventDate.setTime(0),
        "timeZone": moment.tz.guess(),
    },
    "end": {
        "dateTime": !calendarEvent.fAllDayEvent ? calendarEvent.EventDate : calendarEvent.EventDate.setTime(0),
        "timeZone": moment.tz.guess(),
    },
    "location": {
        "displayName": !calendarEvent || !calendarEvent.Location ? "No Location": calendarEvent.Location,
    },
    "isAllDay": !calendarEvent || !calendarEvent.fAllDayEvent ? false : true,
};

context.msGraphClientFactory.getClient()
    .then((client: MSGraphClient) => {
        client.api("/me/calendar/events").post(foobar)
        .then((content: any) => {
            console.log("CalendarService | createCalendarEvent | content: ", content);
        });
    });

这篇关于创建全天活动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆