如何使用 Web API 获取资源的可用性?



CRM 2016揭露了ODATA/Web API,并且可以开箱即用。

使用组织服务,我们可以发出这样的请求:

// Create the van required resource object.
RequiredResource vanReq = new RequiredResource
{
    ResourceId = _vanId,
    ResourceSpecId = _specId
};
// Create the appointment request.
AppointmentRequest appointmentReq = new AppointmentRequest
{
    RequiredResources = new RequiredResource[] { vanReq },
    Direction = SearchDirection.Backward,
    Duration = 60,
    NumberOfResults = 10,
    ServiceId = _plumberServiceId,
    // The search window describes the time when the resouce can be scheduled.
    // It must be set.
    SearchWindowStart = DateTime.Now.ToUniversalTime(),
    SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
    UserTimeZoneCode = 1
};
// Verify whether there are openings available to schedule the appointment using this resource              
SearchRequest search = new SearchRequest
{
    AppointmentRequest = appointmentReq
};
SearchResponse searched = (SearchResponse)_serviceProxy.Execute(search);
if (searched.SearchResults.Proposals.Length > 0)
{
    Console.WriteLine("Openings are available to schedule the resource.");
}

是否可以使用功能/动作或任何其他ODATA功能模仿此功能?

我相信请求应该是这样的:

crmOrg/api/v8.1/Search(AppointmentRequest=@request)?@request=

但是,我不确定如何编码请求的其余部分。

参数如下:

http://yourcrm.org/org/api/data/v8.1/Search(AppointmentRequest=@ar)/?@ar={SearchWindowStart:%272017-01-01%27,Duration:60,NumberOfResults:10}

它是序列化AppointmentRequest类的URL编码JSON。

{
  SearchWindowStart:'2017-01-01',
  Duration: 60,
  NumberOfResults:10,
  etc...
}

更多信息在这里:https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.messages.appointmentrequest.aspx

odata参考:http://odata.github.io/webapi/04-06-function-parameter-support/

最新更新