Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

InvalidPluginExecutionException not working as expected

$
0
0

I'm working with CRM 2013. I have tracing set up, but it's not working correctly for a plugin that's reigstered for the PreValidation stage. I'm getting an error message, but it looks like a javascript message - the dialog box is entitled "Message from Webpage" and it has that yellow exclamation mark you see for a javascript message. I've used tracing a lot in the past, and it's usually just a matter of putting in your tracing statements, and then throwing an exception, and then you're presented with an error box with a button to 'Download Log file'.

This is the image I'm seeing:

Here's my plugin code, maybe someone can spot something here, because I can't!

Thanks.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages; 

namespace VuSolutions.Ca.CRM.OrderVal
{
    public class OrderErrors : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            tracingService.Trace("Entering OrderVal.Execute");
            try
            {
                // Obtain the execution context from the service provider.
                Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                    serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                Validation val = new Validation(service, context);

                Entity entity = (Entity)context.InputParameters["Target"];
                tracingService.Trace("entity: " + entity);
                tracingService.Trace("entity.Attributes.Contains(new_lastvalidateddate)? " + entity.Attributes.Contains("new_lastvalidateddate"));
                PrintOutAttributesTest(entity, serviceProvider);
                if (entity.Attributes.Contains("new_lastvalidateddate")) 
                {
                    Entity EntityImage = (Entity)context.PreEntityImages["EntityImage"];
                    Guid enquiryid = ((Guid)EntityImage.Attributes["new_enquiryid"]);
                    //tracingService.Trace("enquiryid: " + enquiryid);
                    if (enquiryid != Guid.Empty)
                    {
                        tracingService.Trace("Calling GetErrors");
                        string messages = val.GetErrors(enquiryid, serviceProvider);
                        if (messages != string.Empty)
                        {
                            //messages = "&& " +"The following were found. " + messages + " &&";
                            messages = "The following were found. " + messages;
                            //throw new InvalidPluginExecutionException(messages);
                        }
                    }
                }
                throw new InvalidPluginExecutionException();
            }
            catch (InvalidPluginExecutionException invalidEx)
            {
                throw invalidEx;
            }
            catch (Exception ex)
            {
                throw new Exception("Exception in execute of Order Errors " + ex.Message, ex);
            }
        }

        protected internal void PrintOutAttributesTest(Entity entity, IServiceProvider serviceProvider)
        {
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            
            foreach (var attrib in entity.Attributes)
            {
                tracingService.Trace("Attribute key: " + attrib.Key + ", Attribute value: " + attrib.Value.ToString());
            }
        }

    }
}



Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>