Partajați prin


SearchRequest Class

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Contains the data needed to search for available time slots that fulfill the specified appointment request.

For the Web API use the Search Function.

Namespace:   Microsoft.Crm.Sdk.Messages
Assembly:  Microsoft.Crm.Sdk.Proxy (in Microsoft.Crm.Sdk.Proxy.dll)

Inheritance Hierarchy

System.Object
  Microsoft.Xrm.Sdk.OrganizationRequest
    Microsoft.Crm.Sdk.Messages.SearchRequest

Syntax

[DataContractAttribute(Namespace = "https://schemas.microsoft.com/crm/2011/Contracts")]
public sealed class SearchRequest : OrganizationRequest
<DataContractAttribute(Namespace := "https://schemas.microsoft.com/crm/2011/Contracts")>
Public NotInheritable Class SearchRequest
    Inherits OrganizationRequest

Constructors

Name Description
System_CAPS_pubmethod SearchRequest()

Initializes a new instance of the SearchRequest class.

Properties

Name Description
System_CAPS_pubproperty AppointmentRequest

Gets or sets the appointment request.

System_CAPS_pubproperty ExtensionData

Gets or sets the structure that contains extra data. Optional.(Inherited from OrganizationRequest.)

System_CAPS_pubproperty Item[String]

Gets or sets the indexer for the Parameters collection.(Inherited from OrganizationRequest.)

System_CAPS_pubproperty Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)

System_CAPS_pubproperty RequestId

Gets or sets the ID of an asynchronous operation (system job). Optional. (Inherited from OrganizationRequest.)

System_CAPS_pubproperty RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)

Methods

Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

Remarks

Message Availability

For this message to work, the caller must be connected to the server.

Pass an instance of this class to the Execute method, which returns an instance of SearchResponse.

Privileges and Access Rights

For a list of the privileges required, see Search message privileges.

Notes for Callers

This message will return a set of available appointments as time blocks.

Examples

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. For the complete sample, see the link later in this topic.


// 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.");
}

' Create the van required resource object.
Dim vanReq As RequiredResource = New RequiredResource With {.ResourceId = _vanId, .ResourceSpecId = _specId}

' Create the appointment request.
Dim appointmentReq As AppointmentRequest = New AppointmentRequest With { _
    .RequiredResources = New RequiredResource() {vanReq}, .Direction = SearchDirection.Backward, _
    .Duration = 60, .NumberOfResults = 10, .ServiceId = _plumberServiceId, _
    .SearchWindowStart = Date.Now.ToUniversalTime(), .SearchWindowEnd = Date.Now.AddDays(7).ToUniversalTime(), _
    .UserTimeZoneCode = 1}
    ' The search window describes the time when the resouce can be scheduled.
    ' It must be set.

' Verify that the resources have been scheduled                
Dim search As SearchRequest = New SearchRequest With {.AppointmentRequest = appointmentReq}
Dim searched As SearchResponse = CType(_serviceProxy.Execute(search), SearchResponse)

If searched.SearchResults.Proposals.Length > 0 Then
    Console.WriteLine("Scheduled the resources sucessfully.")
End If

Thread Safety

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

SearchResponse
Microsoft.Crm.Sdk.Messages Namespace
Schedules in Microsoft Dynamics 365
Sample: Search for openings to schedule a resource
Appointment entity messages and methods

Return to top

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright