public void Execute(IPluginExecutionContext context) { if (!(context.InputParameters.Contains("Target")) || !(context.InputParameters["Target"] is DynamicEntity)) return; DynamicEntity _opportunity = (DynamicEntity)context.InputParameters["Target"]; if (_opportunity.Name != EntityName.opportunity.ToString()) return; if (!_opportunity.Properties.Contains("new_status")) return; Picklist status = (Picklist)_opportunity["new_status"]; if (status.Value.ToString() != "5") return; ICrmService crmService = context.CreateCrmService(true); DynamicEntity new_stop = new DynamicEntity("new_stop"); Customer oppid = (Customer) _opportunity["opportunityid"]; Lookup oppLookup = new Lookup(); oppLookup.Value = oppid.Value; oppLookup.type = EntityName.opportunity.ToString(); new_stop.Properties.Add(new LookupProperty("new_contractid", oppLookup)); Guid stopGuid = crmService.Create(new_stop); }