Creating and setting the state of a CRM object in a single request

Using this code, I can set the state and status of a CRM object in C #.

SetStateRequest appointmentRequest = new SetStateRequest
{
    State = new OptionSetValue(3), //Scheduled
    Status = new OptionSetValue(5), //Busy
    EntityMoniker = new EntityReference("appointment", myEntity.Id)
};

crmsvc.Execute(appointmentRequest);

A few lines before that I create the same object with

crmsvc.Create(myEntity);

Doing this in two queries seems dumb, so I went looking for a way to do this in one query.

Found this question. I need to set State and StatusCode for a custom object , and it seems that the status code can be set before saving, but I can’t find any patterns that do this also with state.

Tried to do it, but it didn’t work

myEntity["state"] = new OptionSetValue(3);

He throws back:

The entity does not contain an attribute with the name = 'state'. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault) .: The 'Entity' object does not contain an attribute with the name = 'state'.

, - ?

+4
3

, . , CRM , .

. , .

statuscode create.

, , , statecode statuscode, .

+4
+1

CRM. , , , .

, :

1) . , .

2) , statecode/statuscode.

, , .

+1

Source: https://habr.com/ru/post/1535043/


All Articles