Hi, I created a simple plugin to update contact record. Basically, it should clear all the flags from associated records, and set a new flag in one record. It is "Update" message on contact, pre-operation, however, it doesn't triggered at all. please check the below,
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName == "contact") { if (entity.Attributes.Contains("businessregistrationid") == true) { String contactid = entity.Id.ToString(); string registraionid = entity.Attributes["businessregistrationid"].ToString(); string fetchxml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='contact'> <attribute name='businessregistrationid' /> <attribute name='record' /> <attribute name='contactid' /> <filter type='and'> <condition attribute='businessregistrationid' operator='eq' value='"+registraionid+@"'/> </filter> </entity> </fetch>"; EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchxml)); foreach (var c in ec.Entities) { if (c.Attributes["record"].ToString() == contactid) { c.Attributes["record"] = "1"; } else { c.Attributes["ofrecord"] = "0"; } } } } else { throw new InvalidPluginExecutionException("The account number can only be set by the system."); } }
*This post is locked for comments