Hi all,
I written a plugin that works on a dev environnement, and does not work in Live environnement.
This plugin has been simplified now, just to change a integer value (compiled in Framework 4 in both environnements - works on Dev only).
Other plugins (e.g. creates an annotation on this specific entity) works in both environnements.
This Dev environment is a sql copy of Live environnement (CRM organization imported).
This Dev environnement is not on ADFS, Win Server 2012 R2, CRM v6.1.4.145
The Live environnementis on ADFS, Win Server 2008 R2 Std, CRM v6.1.3.119
I tried to get a clear error message, using traces.
But this is not clear, any help is appreciated
Thanks Nicolas
using System; using System.ServiceModel; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; namespace Plugin_DCS { public class sample_USP_OnCreate_changeName:IPlugin { public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "new_pieceutilisee") return; try { IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("rework on usp."); New_pieceutilisee currentUsp = new New_pieceutilisee(); currentUsp.New_pieceutiliseeId = new Guid(context.OutputParameters["id"].ToString()); currentUsp.New_Quantite = 3; tracingService.Trace("rework on usp. tididi"); service.Update(currentUsp); tracingService.Trace("rework on usp. done"); } //<snippetFollowupPlugin3> catch (FaultException<OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the USP_OnCreate_changeName plug-in.", ex); } //</snippetFollowupPlugin3> catch (Exception ex) { tracingService.Trace("USP_OnCreate_changeNamePlugin: {0}", ex.ToString()); throw; } } } } } //</snippetFollowupPlugin>
*This post is locked for comments
Thank you Jarren
In your catch block, if you want you can
throw new InvalidPluginExecutionException(ex.Message + ": " + ex.StackTrace)
to let it show the error on screen when it fails, if it's synchronous.
Use ex.Message and ex.StackTrace to get a better understanding of what's erroring out.
Thanks David,
Now this simplified sample is cleared [removed new Guid(context.OutputParameters["id"].ToString())...]
And it still works only in Dev.
Regarding plugin registration step, on both sides, registration have only one step [ message Create, Post-operation, execution synchronous ], no image.
How can I get a clear error message ? Is there another way to have a clear error (like event viewer) ?
I can't see any reason why this wouldn't work in one environment, but would in another, unless there are differences in the schema for the entities you are accessing, or there are differences in the plugin registration step
However, you can simplify your code, which may help. It looks like you're updating the newly created record using the Update message, but you can instead register the plugin on a pre-stage, and update the attributes of the Target InputParameter directly. If you do this, then you don't need an explicit update. This is more efficient, and may avoid locking issues
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6