hi ,
i have post create plugin in entity A ,
after create plugin i want to update other entity B , that have lookup of A , with new created record ,
but its not work and i have error like this
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #F9613D51Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #F9613D51</Message>
<Timestamp>2018-06-27T04:31:01.6868243Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>
i cant see in sql new created record and when i want to set the id to entity b , Although I see Created record in plugin i cant set it to records of entity B
and i have another question , how can i find error details with Reference number
this is my code sample
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService _service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.MessageName.ToLower() == "create")
{
Entity ExchangeRate = (Entity)context.InputParameters["Target"];
ExchangeRate = _service.Retrieve(ExchangeRate.LogicalName, ExchangeRate.Id, new ColumnSet(true));
QueryExpression FI = new QueryExpression("FI");
FI.ColumnSet = new ColumnSet(true);
FI.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
EntityCollection ECI = _service.RetrieveMultiple((QueryBase)FI);
for (int index = 0; index < ECI.Entities.Count; index++)
{
Entity FIEntity = ECI.Entities[index];
FIEntity["saba_exchangeratefinacialinformationid"] = ExchangeRate.Id;
_service.Update(FIEntity);
}
}
exhangerate is etity A
FI is entity B include lookup of A
thanks for your answer
*This post is locked for comments
No you have to use for each loop only. Nothing is there to update complete entity set in single statement just like in SQL.
thanks for your answer its done ,but i have another question , do we have any way to update whole record with something like stored procedures instead use foreach loop
thanks , its work
You don't need to write any code to get Id, you can simply use like below
Entity ExchangeRate = (Entity)context.InputParameters["Target"]; QueryExpression FI = new QueryExpression("FI"); FI.ColumnSet = new ColumnSet(true); FI.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0); EntityCollection ECI = _service.RetrieveMultiple((QueryBase)FI); for (int index = 0; index < ECI.Entities.Count; index++) { Entity FIEntity = ECI.Entities[index]; FIEntity["saba_exchangeratefinacialinformationid"] = new EntityReference("A entity logicalname",ExchangeRate.Id); _service.Update(FIEntity); }
change this line :FIEntity["saba_exchangeratefinacialinformationid"] = ExchangeRate.Id;
with
FIEntity["saba_exchangeratefinacialinformationid"] = new EntityReference(ExchangeRate.LogicalName , ExchangeRate.Id);
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156