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

CRM Online Retreive Plugin

$
0
0

Hi,

Newbie here in plugins. Can anyone help me about my issue?

Here's my code:

//Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            
            // Obtain the execution context from the service provider.
            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                    serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            
            // The InputParameters collection contains all the data passed in the message request.            
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                //Entity entityWBSDetail = (Entity)context.InputParameters["Target"];
                
                // Obtain the target entity from the input parmameters.
                //EntityReference entityRef = (EntityReference)context.InputParameters["Target"];                
                Guid ParentGuid = Guid.Empty;
                Entity ParentEntity = new Entity("new_wbsdetail");
                Entity CurrEntity = new Entity("new_wbsdetail");

                try
                {
                    tracingService.Trace("create entity Entity");
                    Entity entity = (Entity)context.InputParameters["Target"];
                    //Instead of getting entity from Target, we use the Image

                    //ParentGuid = entity.GetAttributeValue<Guid>("new_parentwbsdetailid");                    
                    tracingService.Trace("Before Entity");
                    CurrEntity = service.Retrieve("new_wbsdetail", entity.Id, new ColumnSet(new string[] { "new_name", "new_parentwbsdetailid" }));
                    tracingService.Trace("After Entity");
                    EntityReference EntityRef = ((EntityReference)(CurrEntity.Attributes["new_parentwbsdetailid"]));
                    tracingService.Trace("My Lookup ID {0}" + EntityRef.Id);
                    ParentEntity = service.Retrieve("new_wbsdetail", EntityRef.Id, new ColumnSet(new string[] { "new_name", "new_parentwbsdetailid" }));
                    tracingService.Trace("Parent Entity {0}", CurrEntity["new_name"]);

                    ParentEntity.Attributes["new_name"] = "test1";
                    //tracingService.Trace("Parent Entity Est No of Hours {0}", ParentEntity["new_estnoofhours"]);
                    
                    tracingService.Trace("Test");
                    service.Update(ParentEntity);
                    tracingService.Trace("AFter Update");                    
                }
                catch (Exception ex)
                {
                    tracingService.Trace("Updating Parent Record: {0}", ex.ToString());
                    throw;
                }                
            }


 And I'm having error

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): UpdateWBSParentDetails.UpdateParentWBSDetails: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ErrorCode>-2147220956</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>Unexpected exception from plug-in (Execute): UpdateWBSParentDetails.UpdateParentWBSDetails: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.</Message>
<Timestamp>2015-11-22T16:11:25.8692087Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>create entity Entity
Before Entity
After Entity
My Lookup ID {0} 01119046-cd90-e511-80f2-3863bb341b70
Parent Entity test
Test
Updating Parent Record: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Unexpected exception from plug-in (Execute): UpdateWBSParentDetails.UpdateParentWBSDetails: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).

Please help. Really need it bad! Thank you.


Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>