Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

update lookup after post create plugin

$
0
0

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 


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images