Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin on specific entity - different environments

(0) ShareShare
ReportReport
Posted on by 2

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

  • Nicolas Pannequin Profile Picture
    2 on at
    RE: Plugin on specific entity - different environments

    Thank you Jarren

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Plugin on specific entity - different environments

    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.

  • Nicolas Pannequin Profile Picture
    2 on at
    RE: Plugin on specific entity - different environments

    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) ?

  • David Jennaway Profile Picture
    14,065 on at
    RE: Plugin on specific entity - different environments

    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

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.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans