CRM 2011 CS: Retrieve the schedule of Multiple users

 

using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,

                                                    serverConfig.HomeRealmUri,

                                                    serverConfig.Credentials,

                                                    serverConfig.DeviceCredentials))

{

    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

 

    // Get the current user's information.

    WhoAmIRequest userRequest = new WhoAmIRequest();

    WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);

    Guid _currentUserId = userResponse.UserId;

 

    // Create another user

    Guid _otherUserId = new Guid("0a4252a0-7e70-11d0-a5d6-28db04c10000");

        

 

    // Retrieve the schedule of the current and the other user.                                           

    QueryMultipleSchedulesRequest scheduleRequest = new QueryMultipleSchedulesRequest();

    scheduleRequest.ResourceIds = new Guid[2];

    scheduleRequest.ResourceIds[0] = _currentUserId;

    scheduleRequest.ResourceIds[1] = _otherUserId;

    scheduleRequest.Start = DateTime.Now;

    scheduleRequest.End = DateTime.Today.AddDays(7);

    scheduleRequest.TimeCodes = new TimeCode[] { TimeCode.Available };

 

    QueryMultipleSchedulesResponse scheduleResponse = (QueryMultipleSchedulesResponse)_serviceProxy.Execute(scheduleRequest);

                   

}