web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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 4

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

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    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

  • Nicolas Pannequin Profile Picture
    4 on at

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

  • Verified answer
    Community Member Profile Picture
    on at

    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
    4 on at

    Thank you Jarren

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans