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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

plugin

(0) ShareShare
ReportReport
Posted on by 1,225

i have registered a plugin. no errors in code. i could build it and register it correctly

but when i trigger the plugin the following error is coming. please suggest me a way to get through.

"An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide."

 

help me.

*This post is locked for comments

I have the same question (0)
  • Hosk Profile Picture
    on at

    How do you expect anyone to be able to diagnose the problem with the information you have provided?

    no code

    not the full error log

    we don't even know what entity the plugin is triggered from, what's it's doing!!!

    So how do you know there are no errors in the code, just because the code compiles doesn't mean it will run without error.

    start with showing us the code at least

  • vinod shivoor Profile Picture
    1,225 on at

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    using Microsoft.Xrm.Sdk.Client;

    using System.ServiceModel;

    namespace AcademicYearSettings2

    {

       public class AYS2 : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

               IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService _service = serviceFactory.CreateOrganizationService(context.UserId);

               if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

               {

                   Entity entity = context.InputParameters["Target"] as Entity;

                   string records = @"

                                    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

                                    <entity name='lead'>

                                       <attribute name='new_region'/>

                                       <attribute name='new_postaldistrictid'/>

                                       <attribute name='new_businesstype'/>

                                       <attribute name='new_industrysector'/>

                                       <attribute name='new_businesstypetext'/>

                                       <attribute name='new_industrysectortext'/>

                                       <attribute name='leadid'/>

                                    </entity>

                                    </fetch> ";

                   EntityCollection result = _service.RetrieveMultiple(new FetchExpression(records));

                   foreach (var c in result.Entities)

                   {

                       if (c.Attributes.Contains("new_businesstype"))

                       {

                           EntityReference buslookup = (EntityReference)c.Attributes["new_businesstype"];

                           if (buslookup != null)

                           {

                               string bus = buslookup.Name;

                               c["new_businesstypetext"] = bus;

                               _service.Update(c);

                           }

                       }

                       if (c.Attributes.Contains("new_industrysector"))

                       {

                           EntityReference indlookup = (EntityReference)c.Attributes["new_industrysector"];

                           if (indlookup != null)

                           {

                               string ind = indlookup.Name;

                               c["new_industrysectortext"] = ind;

                               _service.Update(c);

                           }

                       }

                       EntityReference postallookup = (EntityReference)c.Attributes["new_postaldistrictid"];

                       OptionSetValue op = new OptionSetValue();

                       string first2 = postallookup.Name;

                       first2 = first2.Substring(0, 2);

                       string fullname = postallookup.Name;

                       //london for ENW characters

                       if (fullname == "E1" || fullname == "E1w" || fullname == "E2" || fullname == "E3" || fullname == "E4" || fullname == "E5" || fullname == "E6" || fullname == "E7" || fullname == "E8" || fullname == "E9" || fullname == "E10"

    || fullname == "E11"

    || fullname == "E12" || fullname == "E13" || fullname == "E14" || fullname == "E15" || fullname == "E16" || fullname == "E17" || fullname == "E18" || fullname == "E20" || fullname == "E77" || fullname == "E98" || fullname == "N1"

    || fullname == "N1p" || fullname == "N1c"

    || fullname == "N2" || fullname == "N3" || fullname == "N4" || fullname == "N5" || fullname == "N6" || fullname == "N7" || fullname == "N8" || fullname == "N9" || fullname == "N10" || fullname == "N11" || fullname == "N12" || fullname == "N13"

    || fullname == "N14" || fullname == "N15" || fullname == "N16" || fullname == "N17" || fullname == "N18" || fullname == "N19" || fullname == "N20" || fullname == "N21" || fullname == "N22" || fullname == "N81" || fullname == "W1M"

    || fullname == "W1N" || fullname == "W1P" || fullname == "W1R"

    || fullname == "W1S" || fullname == "W1T" || fullname == "W1U" || fullname == "W1V" || fullname == "W1W" || fullname == "W1X" || fullname == "W1Y" || fullname == "W1K" || fullname == "W1J" || fullname == "W1H" || fullname == "W1G"

    || fullname == "W1F" || fullname == "W1D"

    || fullname == "W1C" || fullname == "W1B" || fullname == "W1A" || fullname == "W2" || fullname == "W3" || fullname == "W4" || fullname == "W5" || fullname == "W6" || fullname == "W7" || fullname == "W8" || fullname == "W9" || fullname == "W10"

    || fullname == "W11" || fullname == "W12" || fullname == "W13" || fullname == "W14")

                       {

                           op.Value = 0;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                        //North England for LSM

                       else if (fullname == "L1" || fullname == "L2" || fullname == "L3" || fullname == "L4" || fullname == "L5" || fullname == "L6" || fullname == "L7" || fullname == "L8" || fullname == "L9" || fullname == "L10" || fullname == "L12" || fullname == "L12" || fullname == "L13"

    || fullname == "L14" || fullname == "L15" || fullname == "L16" || fullname == "L17" || fullname == "L18" || fullname == "L19" || fullname == "L20" || fullname == "L21" || fullname == "L22" || fullname == "L23" || fullname == "L24" || fullname == "L25" || fullname == "L26"

    || fullname == "L27" || fullname == "L28" || fullname == "L29" || fullname == "L30" || fullname == "L31" || fullname == "L32" || fullname == "L33" || fullname == "L34" || fullname == "L35" || fullname == "L36" || fullname == "L37" || fullname == "L38" || fullname == "L39"

    || fullname == "L40" || fullname == "L41" || fullname == "L42" || fullname == "L43" || fullname == "L44" || fullname == "L45" || fullname == "L46" || fullname == "L47" || fullname == "L48" || fullname == "L49" || fullname == "L60" || fullname == "S1" || fullname == "S2"

    || fullname == "S3" || fullname == "S4" || fullname == "S5" || fullname == "S6" || fullname == "S7" || fullname == "S8" || fullname == "S9" || fullname == "S10" || fullname == "S11" || fullname == "S12" || fullname == "S13" || fullname == "S14" || fullname == "S17" || fullname == "S18"

    || fullname == "S19" || fullname == "S20" || fullname == "S21" || fullname == "S25" || fullname == "S26" || fullname == "S30" || fullname == "S31" || fullname == "S32" || fullname == "S33" || fullname == "S35" || fullname == "S36" || fullname == "S40" || fullname == "S41"

    || fullname == "S42" || fullname == "S43" || fullname == "S44" || fullname == "S45" || fullname == "S49" || fullname == "S60" || fullname == "S61" || fullname == "S62" || fullname == "S63" || fullname == "S64" || fullname == "S65" || fullname == "S66" || fullname == "S70"

    || fullname == "S71" || fullname == "S72" || fullname == "S73" || fullname == "S74" || fullname == "S75" || fullname == "M1" || fullname == "M2" || fullname == "M3" || fullname == "M4" || fullname == "M5" || fullname == "M6" || fullname == "M7" || fullname == "M8" || fullname == "M9"

    || fullname == "M10" || fullname == "M12" || fullname == "M12" || fullname == "M13" || fullname == "M14" || fullname == "M15" || fullname == "M16" || fullname == "M17" || fullname == "M18" || fullname == "M19" || fullname == "M20" || fullname == "M21" || fullname == "M22"

    || fullname == "M23" || fullname == "M24" || fullname == "M25" || fullname == "M26" || fullname == "M27" || fullname == "M28" || fullname == "M29" || fullname == "M30" || fullname == "M31" || fullname == "M32" || fullname == "M33" || fullname == "M34" || fullname == "M35"

    || fullname == "M36" || fullname == "M37" || fullname == "M38" || fullname == "M40" || fullname == "M41" || fullname == "M43" || fullname == "M44" || fullname == "M45" || fullname == "M46" || fullname == "M50" || fullname == "M52" || fullname == "M60" || fullname == "M61"

    || fullname == "M90" || fullname == "M99")

                       {

                           op.Value = 1;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                        //South England for b

                       else if (fullname == "B1" || fullname == "B2" || fullname == "B3" || fullname == "B4" || fullname == "B5" || fullname == "B6" || fullname == "B7" || fullname == "B8" || fullname == "B9" || fullname == "B10"

    || fullname == "B11" || fullname == "B12" || fullname == "B13" || fullname == "B14" || fullname == "B17" || fullname == "B18" || fullname == "B19" || fullname == "B20" || fullname == "B21" || fullname == "B22"

    || fullname == "B23" || fullname == "B24" || fullname == "B25" || fullname == "B26" || fullname == "B27" || fullname == "B28" || fullname == "B29" || fullname == "B30" || fullname == "B31" || fullname == "B32"

    || fullname == "B33" || fullname == "B34" || fullname == "B35" || fullname == "B36" || fullname == "B37" || fullname == "B38" || fullname == "B40" || fullname == "B42" || fullname == "B43"

    || fullname == "B44" || fullname == "B45" || fullname == "B46" || fullname == "B47" || fullname == "B48" || fullname == "B49" || fullname == "B50" || fullname == "B60" || fullname == "B61")

                       {

                           op.Value = 2;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                       //Scotland for G

                       else if (fullname == "G1" || fullname == "G2" || fullname == "G3" || fullname == "G4" || fullname == "G5" || fullname == "G6" || fullname == "G7" || fullname == "G8"

    || fullname == "G9" || fullname == "G10" || fullname == "G11" || fullname == "G12" || fullname == "G13" || fullname == "G14" || fullname == "G15" || fullname == "G16" || fullname == "G17" || fullname == "G18" || fullname == "G19" || fullname == "G20"

    || fullname == "G21" || fullname == "G22" || fullname == "G23" || fullname == "G24" || fullname == "G25" || fullname == "G26"

    || fullname == "G27" || fullname == "G28" || fullname == "G29" || fullname == "G30" || fullname == "G31" || fullname == "G32" || fullname == "G33" || fullname == "G34" || fullname == "G35" || fullname == "G36" || fullname == "G37" || fullname == "G38"

    || fullname == "G39" || fullname == "G40" || fullname == "G41" || fullname == "G42" || fullname == "G43" || fullname == "G44"

    || fullname == "G45" || fullname == "G46" || fullname == "G47" || fullname == "G48" || fullname == "G49" || fullname == "G50" || fullname == "G51" || fullname == "G52" || fullname == "G53" || fullname == "G54" || fullname == "G55" || fullname == "G56"

    || fullname == "G57" || fullname == "G58" || fullname == "G59" || fullname == "G60" || fullname == "G61" || fullname == "G62"

    || fullname == "G63" || fullname == "G64" || fullname == "G65" || fullname == "G66" || fullname == "G67" || fullname == "G68" || fullname == "G69" || fullname == "G70" || fullname == "G71" || fullname == "G72" || fullname == "G73" || fullname == "G74"

    || fullname == "G75" || fullname == "G76" || fullname == "G78" || fullname == "G79")

                       {

                           op.Value = 3;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                       // London

                       else if (first2 == "BR" || first2 == "CR" || first2 == "EC" || first2 == "EN" || first2 == "HA" || first2 == "IG" || first2 == "KT" || first2 == "NW"

                           || first2 == "RM" || first2 == "SE" || first2 == "SM" || first2 == "SW" || first2 == "TW" || first2 == "UB" || first2 == "WC")

                       {

                           op.Value = 0;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                        //North England

                       else if (first2 == "BB" || first2 == "BD" || first2 == "BL" || first2 == "CA" || first2 == "CH" || first2 == "CW" || first2 == "DH" || first2 == "DL"

                         || first2 == "DN" || first2 == "FY" || first2 == "HD" || first2 == "HG" || first2 == "HU" || first2 == "HX" || first2 == "LA" ||

                         first2 == "LN" || first2 == "LS" || first2 == "NE" || first2 == "NG" || first2 == "OL" || first2 == "PR" ||

                         first2 == "SK" || first2 == "SR" || first2 == "ST" || first2 == "TS" || first2 == "WA" || first2 == "WF" || first2 == "WN" || first2 == "YO")

                       {

                           op.Value = 1;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                       // south england

                       else if (first2 == "AL" || first2 == "BA" || first2 == "BH" || first2 == "BN" || first2 == "BS" || first2 == "CB" || first2 == "CM"

                           || first2 == "CO" || first2 == "CT" || first2 == "CV" || first2 == "DA" || first2 == "DE" || first2 == "DT" || first2 == "DY"

                           || first2 == "EX" || first2 == "GL" || first2 == "GU" || first2 == "HP" || first2 == "HR" || first2 == "IP" || first2 == "LE"

                           || first2 == "LU" || first2 == "ME" || first2 == "MK" || first2 == "NN" || first2 == "NR" || first2 == "OX" || first2 == "PE"

                           || first2 == "PL" || first2 == "PO" || first2 == "RG" || first2 == "RH" || first2 == "SG" || first2 == "SL" || first2 == "SN"

                           || first2 == "SO" || first2 == "SP" || first2 == "SS" || first2 == "SY" || first2 == "TA" || first2 == "TF" || first2 == "TN"

                           || first2 == "TQ" || first2 == "TR" || first2 == "WD" || first2 == "WR" || first2 == "WS" || first2 == "WV")

                       {

                           op.Value = 2;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                        //scotland

                       else if ((first2 == "DD") || (first2 == "AB") || (first2 == "EH") || (first2 == "DG") || (first2 == "HS") || (first2 == "FK") ||

                           (first2 == "HS") || (first2 == "IV") || (first2 == "KA") || (first2 == "KW") || (first2 == "KY") || (first2 == "LD") || (first2 == "ML")

                           || (first2 == "PA") || (first2 == "PH") || (first2 == "TD") || (first2 == "ZE"))

                       {

                           op.Value = 3;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                       //Wales

                       else if ((first2 == "CF") || (first2 == "LL") || (first2 == "NP") || (first2 == "SA"))

                       {

                           op.Value = 4;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                       else if (first2 == "BT")

                       {

                           op.Value = 5;

                           c["new_region"] = op;

                           _service.Update(c);

                       }

                   }

               }

           }

       }

    }

  • vinod shivoor Profile Picture
    1,225 on at

    the above is the code.

    its on lead entity.

    trigger: when create an account and save it.

    it should update all the lead records in the organization withe the specified fields in the code.

  • AaronRic Profile Picture
    10,035 on at

    I would recommend gathering the CRM platform traces to identify what is happening immediately before the error occurs.

  • Suggested answer
    Hosk Profile Picture
    on at

    I would simplify the plugin

    remove most of the code and just add small chunks in to try and work out what is working and where the problem maybe occuring.

    You could also try debugging the plugin using the Plugin registration tool

    http://ssharmacrm.wordpress.com/2013/01/03/how-to-debug-dynamics-crm-online-plugin/

    http://inogic.com/blog/2012/06/how-to-debug-plugins-using-profiler/

    http://missdynamicscrm.blogspot.de/2014/05/debug-crm-2013-using-plugin-profiler.html

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Vinod,

    To track, you can use Plugin profiler or you can try to add this into your code:

    throw new InvalidPluginExecutionException("message")

    or

    throw new InvalidPluginExecutionException(ex.message)

    under the try catch...

    Or you can use tracing..

    //Create the tracing service

    ITracingService tracingService = executionContext.GetExtension<ITracingService>();

    tracingService.Trace("first code passed");

    Using the tracingservice, you can get the log and your own message to identify, which line of code, you have passed.

    https://community.dynamics.com/crm/b/crminogic/archive/2011/01/17/use-tracing-in-crm-2011-plugins.aspx

    http://mscrmtech.com/mscrm-2011-useful-itracingservice-addiion-when-creating-plugin-assemblies/

    Hope this helps!

    Thanks.

  • Suggested answer
    Andre Margono Profile Picture
    2,602 on at

    I would also recommend to do try catch and depends on the deployment model of your CRM might be useful to attach a debugger to trace your code. Ref: msdn.microsoft.com/.../gg328574.aspx

    This is my review on the code that potentially become the source of the problem:

    • EntityReference postallookup = (EntityReference)c.Attributes["new_postaldistrictid"]; < This could be potential null exception.
    • When I'm reading your code, it seems you are calling update request so many time. Can you combine the update requests for each items from your query result in 1 request at the end of the operation? This could potentially pump-up your CRM server with too many requests to process
    • The lead query seems to pick ALL leads without any filter, this could potentially causing problem due to the number of the records that retrieved and processed by your plugin.
  • Community Member Profile Picture
    on at

    Vinod,

    Wondering if you are able to resolve the issue based on the suggestions given in the forum.  

    Interesting to know how you resolved and the root cause to help others who encounter similar issues.

    Appreciate if you could share.

    Harihar

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans