Notifications
Announcements
No record found.
When I create an entity the plugin does the expected validation of checking if there is a null value in an attribute.But if I take an existing entity and delete the contents of that field and click on save, I expected that plugin to kick in and throw the error message. but it won't.Please see the screen shots for "Update" and "Create" stepsnamespace ClassLibrary1 { public class TrainingConfig_Valiation_Plugin :IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); Entity entity = (Entity)context.InputParameters["Target"]; /* if (entity.Contains("ita_notestallowedmessage")) { if (String.IsNullOrEmpty(entity.GetAttributeValue<string>("ita_notestallowedmessage"))) { throw new InvalidPluginExecutionException("You cannot have a null value in the notesallowed field"); } } */ if (entity.Contains("ita_notestallowedmessage")) { if (entity.GetAttributeValue<string>("ita_notestallowedmessage") == null) { throw new InvalidPluginExecutionException("You Cannot have null in notesallowed field"); } } else { throw new InvalidPluginExecutionException("You Cannot have null in notesallowed field"); } } } }
*This post is locked for comments
I have to ask why are you doing the above - why haven't you just made the ita_notestallowedmessage a mandatory field?
As for why your plugin isn't working on update -that's because it's only triggered if ita_notestallowedmessage has been updated, otherwise it won't be triggered.
Ben,
I take an existing entity (record) and update the data in ita_notestallowedmessage field (like deleting content of that field). after deleting the content, when save is clicked this plugin should kick and throw error message saying the content of ita_notestallowedmessage is null.
But it won't trigger at all. Even though the content of ita_notestallowedmessage is empty, the entity gets saved.
Do you know if the plugin is executing at all, to at least see if it's something in your code versus the plugin registration? Try just sticking a trace message at the very start of the plugin and check the plugin trace log.
BTW, I am new to MSD CRM. I am practicing developing plugin's. I am use we can make that field mandatory or write javascript
The plugin gets triggered fine (Business process error window popsup) during "Create" step if I don't put anything into ita_notestallowedmessage field (meaning when it is null).
But when I take an existing entity and delete the content of ita_notestallowedmessage field, and hit save button, I expect the plugin to trigger again. But it saves instead.
Where are trace logs available for "online" CRM ? I have a trial membership only. And how to put trace messages in the code?
Hi,
I guess this is because when you are deleting the value, CRm is treating that value as empty (i.e. not null). So the below check doesn't return true-
if (entity.GetAttributeValue<string>("ita_notestallowedmessage") == null)
If you put an additional else for this if and throw sum message then you will see the message.
Basically, if you replace the above if condition with below, you should get a message-
if (string.IsNullOrEmpty(entity.GetAttributeValue<string>("ita_notestallowedmessage")))
Hope this helps.
Ravi
works.
Thank you so much
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2