开发者

Mark an appointment as Scheduled in CRM 2011

I have a Silverlight application that creates an appointment but since it's not marked as "Scheduled" it will not show up in the Calendar. I am using the SOAP service for this, and here is some sample code that fires on a button click that creates an appointment but it does not show up in the Calendar:

TestCommand = new RelayCommand(() =>
{
    var soapCtx = ServiceHelper.GetSingletonSoapService();
    var activityId = Guid.NewGuid();
    var appt = new Entity()
    {
        Id = activityId,
        LogicalName = "appointment"
    };

    appt["activityid"] = activityId;
    appt["scheduledstart"] = DateTime.Now.Date;
    appt["scheduledend"] = DateTime.Now.Date.AddHours(1);
    appt["description"] = "Test 1 2 3";
    appt["subject"] = "Test Command Button Appointment";
    appt["location"] = "Location 1 2 3";

    soapCtx.BeginCreate(appt, ar =>
        {
      开发者_JAVA百科      var response = soapCtx.EndCreate(ar);                                           
            var bookRequest = new OrganizationRequest();

            bookRequest.RequestName = "Book";
            bookRequest["Target"] = appt;
            soapCtx.BeginExecute(bookRequest, 
                new AsyncCallback(OnBookRequestedCompleted), soapCtx);

        }, null);                

});

void OnBookRequestedCompleted(IAsyncResult ar)
{
    var soapCtx = (IOrganizationService)ar.AsyncState;
    var response = soapCtx.EndExecute(ar);      
}

I keep getting "NotFound" exception in the OnBookRequestedCompleted method. Is there a different way of doing this?


Use Fiddler to debug your HTTP request/response and this will give you details about the 'Not Found' exception.


You should not be setting the ActivityId field it is returned by the BookRequest. if BookResponse.ValidationResult.ValidationSuccess == true, apptId = BookResponse.ValidationResult.ActivityId

You need to call SetStateRequest with the id returned by the BookRequest to set the state to Scheduled

For example:

                SetStateRequest state = new SetStateRequest();
                state.State = new OptionSetValue(3);   // Scheduled
                state.Status = new OptionSetValue(5);  // Busy
                state.EntityMoniker = new EntityReference("appointment", apptId);
                SetStateResponse stateSet = (SetStateResponse)this.orgService.Execute(state);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜