have to update new_closed field when entity incident status is set to

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
I have to update new_closed field when entity incident status is set to "resolved" (closed")
I registered my plugin :
Message : Close
Entity: incident
All Attributes
Plugin :
if (context.InputParameters.Properties.Contains("IncidentResolution") &&
context.InputParameters.Properties["IncidentResolution"] is Microsoft.Crm.Sdk.DynamicEntity)
{
entity = (DynamicEntity)context.InputParameters.Properties["IncidentResolution"];
Lookup pl = (Lookup)entity.Properties["incidentid"];
incidentId = pl.Value;
ICrmService iservice = (ICrmService)context.CreateCrmService(true);
DynamicEntity inc = new DynamicEntity();
inc.Name = EntityName.incident.ToString();
TargetRetrieveDynamic target = new TargetRetrieveDynamic();
target.EntityName = inc.Name;
target.EntityId = incidentId;
RetrieveRequest retrieve = new RetrieveRequest();
retrieve.Target = target;
retrieve.ColumnSet = new AllColumns();
retrieve.ReturnDynamicEntities = true;
RetrieveResponse retrieved = (RetrieveResponse)iservice.Execute(retrieve);
inc = (DynamicEntity)retrieved.BusinessEntity;
if (((Status)inc.Properties["statuscode"]).Value == 5)
{
CrmDateTimeProperty closedate = new CrmDateTimeProperty();
closedate.Name = "new_closedate";
closedate.Value = new CrmDateTime();
closedate.Value = ConvertToCRMDateTime(DateTime.Now);
inc.Properties.Add(closedate);
iservice.Update(inc);
}
}
But I get SoapException :
SoapException : Server was unable to process request.
SoapException Detail :
0x8004022e
The object cannot be updated because it is read-only.
Platform