Asked by:
Problem in Contact Entity.

Question
-
Hi,
I want to update one field "description" contact entity. I am using this code but getting error
Entity contact = new Entity("contact");
contact["description"] = "Test11";
contact["contactid"] = context.PrimaryEntityId;
service.Update(contact);Thanks
Regard
Sangram
Monday, August 26, 2013 12:18 PM
All replies
-
Hi,
I think you replace
contact["contactid"] = context.PrimaryEntityId;
with
Entity entity=(Entity)context.InputParameters["Target"];
contact["contactid"] =new Guid(entity.Id.ToString());Monday, August 26, 2013 12:37 PM -
Hi,
Just replace
contact["contactid"] = context.PrimaryEntityId;
with
contact.Id= context.PrimaryEntityId;
Best regards
Steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.atMonday, August 26, 2013 12:50 PM -
I have replace and run but still getting error
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The context is not currently tracking the 'contact' entity.
Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<KeyValuePairOfstringanyType>
<a:key>CallStack</a:key>
<a:value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema"> at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.EnsureTracked(Entity entity, String parameterName)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.UpdateObject(Entity entity, Boolean recursive)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.UpdateObject(Entity entity)
at CrmPackage.Plugins.PostContactUpdate.ExecutePostContactUpdate(LocalPluginContext localContext)
at CrmPackage.Plugins.Plugin.Execute(IServiceProvider serviceProvider)
at PluginProfiler.Library.PluginAppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)</a:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>The context is not currently tracking the 'contact' entity.</Message>
<Timestamp>2013-08-26T18:57:19.366228Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>microsoft blog
Monday, August 26, 2013 6:58 PM -
I have change the code as u mentioned but still getting fallowing error
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The context is not currently tracking the 'contact' entity.
Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<KeyValuePairOfstringanyType>
<a:key>CallStack</a:key>
<a:value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema"> at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.EnsureTracked(Entity entity, String parameterName)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.UpdateObject(Entity entity, Boolean recursive)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.UpdateObject(Entity entity)
at CrmPackage.Plugins.PostContactUpdate.ExecutePostContactUpdate(LocalPluginContext localContext)
at CrmPackage.Plugins.Plugin.Execute(IServiceProvider serviceProvider)
at PluginProfiler.Library.PluginAppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)</a:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>The context is not currently tracking the 'contact' entity.</Message>
<Timestamp>2013-08-26T18:57:19.366228Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>thanks
microsoft blog
Monday, August 26, 2013 6:59 PM -
Hi,
Please trace the value of context.PrimaryEntityName and context.PrimaryEntityId using the ITracingService and purposely throw an InvalidPluginExecutionException.
Next, check that the PrimaryEntityName is indeed the "contact" and that the PrimaryEntityId is the correct ID of the record which triggered the event.
Wednesday, August 28, 2013 9:31 AM -
Hi,
Try the following code using Input & Output parameters:
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "account")
{ Entity contact = new Entity("contact");
contact["description"] = "Test11";
Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
contact["contactid"] = new EntityReference("contact", regardingobjectid);
service.Update(contact);
}
}
Naren
Wednesday, August 28, 2013 10:39 AM