How do I update state (open,complete) in a silverlight/odata project for Dynamics CRM 2011
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(OnChangesSave开发者_如何转开发d, 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.
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.
精彩评论