Hi
I have a plugin firing on "Create", "Preoperation" on "annotation".
It is very simple I want to modify the "notetext" and that is it.
When the plugin runs, and I confirm this by throwing an InvalidPluginExecutionException, the record is not modified.
I don't throw the exception when testing to see if the record is modified.
Is there any restriction on updating an annotation from a plugin?
Has anyone else experienced a similar problem?
Thanks in advanced.
Paul
The code also includes some other things I have tried and are commented out.
public partial class TagNoteWithWeb : BasePlugin { public TagNoteWithWeb(string unsecureConfig, string secureConfig) : base(unsecureConfig, secureConfig) { // Register for any specific events by instantiating a new instance of the 'PluginEvent' class and registering it base.RegisteredEvents.Add(new PluginEvent() { Stage = eStage.PreOperation, MessageName = "Create", EntityName = "annotation", PluginAction = ExecutePluginLogic }); } public void ExecutePluginLogic(IServiceProvider serviceProvider) { // Use a 'using' statement to dispose of the service context properly // To use a specific early bound entity replace the 'Entity' below with the appropriate class type using (var localContext = new LocalPluginContext<Entity>(serviceProvider)) { // Todo: Place your logic here for the plugin var context = localContext.PluginExecutionContext; Entity entity = new Entity(); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "annotation") { localContext.Log("Plug-in not registered correctly, entity is " + entity.LogicalName + ".", System.Diagnostics.EventLogEntryType.Error); localContext.Trace("Plug-in not registered correctly, entity is " + entity.LogicalName + "."); } } if (entity.Attributes.Contains("notetext")) { if (!entity.Attributes["notetext"].ToString().Contains("*WEB*")) { string tempText = entity.Attributes["notetext"].ToString() + " *WEB*"; //string tempText = entity.Attributes["notetext"].ToString() + Environment.NewLine + "*WEB*"; //entity.Attributes.Remove("notetext"); //entity.Attributes.Add("notetext", tempText); entity.Attributes["notetext"] = tempText; entity.Attributes["subject"] = tempText; //throw new InvalidPluginExecutionException(entity.Attributes["notetext"].ToString()); } } else { entity.Attributes.Add("notetext", "*WEB*"); } } } }
*This post is locked for comments
I don't know any limitations. Your code seems fine and you are doing the right by updating the notetext in the PreOperation.
Code looks good but make some changes to avoid any chance of error like
you are checking NoteText by
if (entity.Attributes.Contains("notetext")) { if (!entity.Attributes["notetext"].ToString().Contains("*WEB*")) { //Code here } }
But in case of null notetext ,it will throw error .So in place of
entity.Attributes["notetext"].ToString() write
Convert.ToString(entity.Attributes["notetext"]).
Did you figure out a solution by any chance? We're having the same issue...
Hi,
What error are you getting? Can you paste the error?
I'd also create a version of your annotation plug-in that simply sets the notetext to "ABC" or whatever on pre-operation of a new note, removing all other logic. This will show that it's possible to override the note text. Then it's a matter of determining why the current plug-in isn't working.
Hi Tim
Thanks for the reply.
I have several other plugins similarly created for other entities and they all work as required.
I will try the trace thing and see if that can point to anything amiss.
Paul
I've done a similar thing in the past with the annotation entity without a problem. And your code looks ok.
Do you have other plug-ins that update an entity record pre-operation? I'm asking because it looks like you are using a plug-in framework (BasePlugin) and it could be that something there has been modified or is possibly trapping an exception.
If you create another plug-in that simply puts an "X" or something after a contact's last name when you create a contact (assuming you're in a dev environment) then that will either work, or not, and that will give you more information to work with. Also, in your current plug-in, you can add Trace statements to help view the path that your code is taking.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156