Hello,
below is my code. I'm having a hard time figuring out when to use Guid or Entity Reference, which I think causes the error. But I might be wrong.
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity Order = (Entity)context.InputParameters["Target"]; IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { Guid orderId = Order.Id; if (Order.GetAttributeValue("zst_case") != Guid.Empty) //zst_case is lookup field { decimal inputQuantity = 1; Entity orderProduct = new Entity("salesorderdetail"); orderProduct.Attributes.Add("salesorderid", orderId); //salesorderis is lookup field orderProduct.Attributes.Add("quantity", inputQuantity); //quantity is decimal field service.Create(orderProduct); } } catch (FaultException ex) { throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex); } catch (Exception ex) { tracingService.Trace("FollowUpPlugin: {0}", ex.ToString()); throw; }