Partager via


AddRecurrenceRequest Class

Definition

Contains the data that is needed to add recurrence information to an existing appointment.

public ref class AddRecurrenceRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
[System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/crm/2011/Contracts")]
public sealed class AddRecurrenceRequest : Microsoft.Xrm.Sdk.OrganizationRequest
[<System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/crm/2011/Contracts")>]
type AddRecurrenceRequest = class
    inherit OrganizationRequest
Public NotInheritable Class AddRecurrenceRequest
Inherits OrganizationRequest
Inheritance
AddRecurrenceRequest
Attributes

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 instance.

/// <summary>
/// Demonstrates the AddRecurrence message
/// </summary>
/// <param name="service">The authenticated IOrganizationService instance</param>
/// <param name="appointmentId">The ID of an appointment to convert to a recurring appointment.</param>
static void AddRecurrenceExample(IOrganizationService service,
      Guid appointmentId)
{
      // Retrieve the original appointment subject to verify
      // at the end.
      string appointmentSubject = service
         .Retrieve(
            entityName:"appointment", 
            id: appointmentId, 
            columnSet: new ColumnSet("subject"))
         .GetAttributeValue<string>("subject");

      // Represents the RecurrenceRule.RecurrencePatternType choice column options
      var RecurrencePatternTypes = new
      {
         Daily = 0,
         Weekly = 1,
         Monthly = 2,
         Yearly = 3
      };

      // Represents the bitmask values for RecurrenceRule.DaysOfWeekMask column
      var DayOfWeek = new
      {
         Sunday = 0x01,
         Monday = 0x02,
         Tuesday = 0x04,
         Wednesday = 0x08,
         Thursday = 0x10,
         Friday = 0x20,
         Saturday = 0x40
      };

      // Represents the RecurrenceRule.PatternEndType choice column options
      var RecurrenceRulePatternEndType = new
      {
         NoEndDate = 1,
         Occurrences = 2,
         PatternEndDate = 3
      };


      // Instantiate a RecurringAppointmentMaster entity instance to specify 
      // the recurrence information.
      // Other appointment details such as'subject' and 'location' are copied
      // from the existing appointment to the recurring appointment master object.
      Entity recurringAppointmentInfo = new("recurringappointmentmaster")
      {
         Attributes =
         {
            { "starttime",DateTime.Now.AddHours(2)},
            { "endtime", DateTime.Now.AddHours(3) },
            { "recurrencepatterntype", 
                  new OptionSetValue(RecurrencePatternTypes.Weekly) },
            { "interval",1 },
            { "daysofweekmask",DayOfWeek.Thursday },
            { "patternstartdate",DateTime.Today },
            { "patternendtype",
                  new OptionSetValue(RecurrenceRulePatternEndType.Occurrences) },
            { "occurrences",5 },
         }
      };


      // Use the AddRecurrence message to convert the existing appointment
      // object to a recurring appointment master object. The existing
      // appointment object is deleted.
      AddRecurrenceRequest request = new()
      {
         Target = recurringAppointmentInfo,
         AppointmentId = appointmentId
      };

      var response = (AddRecurrenceResponse)service.Execute(request);
      Guid recurringAppointmentMasterId = response.id;

      // Verify that the newly created recurring appointment master has same 'subject' 
      // as the existing appointment.
      string retrievedMstrApptSubject = service
         .Retrieve(
               entityName: "recurringappointmentmaster", 
               id: recurringAppointmentMasterId, 
               columnSet: new ColumnSet("subject"))
         .GetAttributeValue<string>("subject");

      if (retrievedMstrApptSubject == appointmentSubject)
      {
         Console.WriteLine($"{appointmentSubject} was converted to a recurring appointment.");
      }
}

You can try the AddRecurrenceExample method above using the Quickstart: Execute an SDK for .NET request (C#) and using the following Main method:

static void Main()
{
      IOrganizationService service = new ServiceClient(conn);

      //Define an appointment
      Entity appointment = new("appointment")
      {
         Attributes =
         {
            {"subject", "Example Appointment" },
            {"scheduledstart", DateTime.Now.AddHours(2) },
            {"scheduledend", DateTime.Now.AddHours(3) },
         }
      };
      // Create an appointment
      Guid apptId = service.Create(appointment);

      // Try the example method
      AddRecurrenceExample(service, apptId);
}

Remarks

For the Web API use the AddRecurrence action.

Usage

Pass an instance of this class to the Execute(OrganizationRequest) method, which returns an instance of the AddRecurrenceResponse class.

Privileges and Access Rights

To perform this action, the caller must have privileges on the RecurringAppointmentMaster and Appointment tables, and access rights on the specified record in the Target property.

Notes for Callers

When you convert an existing appointment to a recurring appointment by using this message, the data from the existing appointment is copied to a new recurring appointment master instance, and the existing appointment record is deleted.

Constructors

AddRecurrenceRequest()

Initializes a new instance of the AddRecurrenceRequest class.

Properties

AppointmentId

Gets or sets the ID of the appointment that needs to be converted into a recurring appointment. Required.

ExtensionData

Gets or sets the structure that contains extra data. Optional.

(Inherited from OrganizationRequest)
Item[String]

Gets or sets the indexer for the Parameters collection.

(Inherited from OrganizationRequest)
Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RequestId

Gets or sets the ID of the request. Optional.

(Inherited from OrganizationRequest)
RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
Target

Gets or sets the target, which is a recurring appointment master record to which the appointment is converted. Required.

Applies to

See also