1

I have a silverlight app hosted in CRM 2011 online. I have functionality where I am updating a phone call and display two fields in a small form. I have the requirement to mark as complete but I seem to be failing here.

I have:

phoneCall.StateCode.Value = 1;

phoneCall.Subject = activity.Subject;
phoneCall.Description = activity.Description;

_context.UpdateObject(phoneCall);
_context.BeginSaveChanges(OnChangesSaved, phoneCall);

The subject works and saves as well as the description but the statecode does not. StateCode is not null this is an existing object and it's currently set to 0 (open). The save does not affect the StateCode. I have this in a try-catch and no error is being reported.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jonathan Kaufman
  • 314
  • 2
  • 15

1 Answers1

2

The status of a record cannot be changed with an Update message. In order to change the statecode or status code, you have to issue a SetStateRequest.

var setStateRequest = new SetStateRequest
{
  EntityMoniker = new EntityReference({LogicalName}, {Id}),
  State = new OptionSetValue(1),
  Status = new OptionSetValue(1)
};

_context.Execute(setStateRequest);

Update


The REST endpoint has some limitations.

The REST endpoint provides an alternative to the WCF SOAP endpoint, but there are currently some limitations.

  • Only Create, Retrieve, Update and Delete actions can be performed on entity records Messages that require the Execute method cannot be performed.

This means for you: you cannot alter the state with the REST endpoint. You have to use the WCF SOAP endpoint for this task.

ccellar
  • 10,326
  • 2
  • 38
  • 56
  • The SetStateRequest is used in the SDK I am using the REST service in a silverlight app hosted on CRM 2011 Online. SetStateRequest does not exist in that service. – Jonathan Kaufman May 18 '11 at 18:46