首页 > 解决方案 > EWS-javascript-api 可用性问题

问题描述

请任何人都可以帮助使用 ews-javascript-api 中的 GetUserAvailability 方法。我目前正在使用这个交换 api 开发一个房间预订系统,但是我遇到了一个我找不到解决方案的问题。请需要你的帮助

const room = 'roomemail@email.com' 
const user = 'email@email.com' 
var myPwd = 'password'

// Dependencies
var ews = require("ews-javascript-api");

// Debug Mode
ews.EwsLogging.DebugLogEnabled = false;

// Login to Exchange URI, Username and Password, Version of Exchange
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
exch.Credentials = new ews.ExchangeCredentials(user, myPwd);  
exch.Url = new ews.Uri("https://mail.domain.com");

// Check Availability
var now = new Date();
now.setMinutes(now.getMinutes() + 1);

var startTime = new ews.DateTime(now);
var tw = new ews.TimeWindow(ews.DateTime.Now, ews.DateTime.Now.AddHours(8));
var attendee = new ews.AttendeeInfo("roomemail@email.com");
var result = new exch.GetUserAvailability(attendee, tw, ews.AvailabilityData.FreeBusyAndSuggestions);

console.log(result);

然后我得到了这个错误:

../ews-javascript-api/js/Core/EwsUtilities.js:567 throw new ArgumentException_1.ArgumentException(Strings_1.Strings.CollectionIsEmpty, paramName); ^ 例外:集合为空。在新的 ExchangeService.GetUserAvailability (/Users/rsatriaj) 处的 Function.EwsUtilities.ValidateParamCollection (/Users/rsatriaj/node_modules/ews-javascript-api/js/Core/EwsUtilities.js:567:19) /node_modules/ews-javascript-api/js/Core/ExchangeService.js:1402:37)在对象。(/Users/rsatriaj/booking.js:46:14) 在 Module._compile (module.js:652:30) 在 Object.Module._extensions..js (module.js:663:10) 在 Module.load ( module.js:565:32) 在 tryModuleLoad (module.js:505:12) 在 Function.Module._load (module.js:497:3) 在 Function.Module.runMain (module.js:693:10) 在启动(bootstrap_node.js:191:

到目前为止,我不确定该怎么做。你们能帮我解决这个问题吗?任何信息都有帮助!真的很感激

标签: javascriptnode.jsexchangewebservicesews-javascript-api

解决方案


GetUserAvailability不是类,它是类中的方法ExchangeService。它还需要参加者的数组,而不仅仅是一个,这将返回一个承诺,而不是像 c# 版本中的同步代码。您可以使用.then或不使用.catch

您也可以在最新节点中将它与 async await 一起使用。

在异步函数内部时
var result = await exch.GetUserAvailability([attendee], tw, ews.AvailabilityData.FreeBusyAndSuggestions);

使用承诺时
exch.GetUserAvailability([attendee], tw, ews.AvailabilityData.FreeBusyAndSuggestions).then(function(result){/* do something with result*/}, function(error){/* do something when error occur*/})


推荐阅读