how the plugin is executed (pre, post, async, sync) and the registration of images (pre, post) and their attributes is done entirely with Plugin Registration Tool (by the executable from nuget or using the one inside XrmToolBox) in your code I don't think it's necessary that Merge operation that you are doing (because I don't know how it will merge the attributes) but if you are in a post sync, the attributes on the image will be the same as the attributes of the target/current entity. also in your check I would avoid the use of Contains, Contains returns if the attribute is present inside the collection of attributes or not (and you can have a case where the attribute is there but is null for example) I would use the GetAttributeValue, something like this string year = postImage.GetAttributeValue ("year"); if (String.IsNullOrWhiteSpace(year)) { throw new InvalidPluginExecutionException(OperationStatus.Failed, "Year is empty!"); } in my code I assumed that year is a string, if is a whole number you should use an int? int? year = postImage.GetAttributeValue ("year"); if (!year.HasValue) { throw new InvalidPluginExecutionException(OperationStatus.Failed, "Year is empty!"); } to summarize: 1) just use a post image with just these two attributes 2) use GetAttributeValue instead of Contains to check if the value is actually null
↧