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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

An unexpected error occurred from ISV code

(0) ShareShare
ReportReport
Posted on by

Hi ,

i made a plugin to check some condition .

so if that condition is not equal it show custom error message but it show in some different message 

can plz any one suggest that how to solve that problem

error show in that:

An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): TestPlugin.ImageDemo: System.Exception: The field  count is Zero.
pastedimage1565338532517v1.png
but i want to show only The field  count is Zero..

*This post is locked for comments

  • Sateesh123 Profile Picture
    on at
    RE: An unexpected error occurred from ISV code

    Hi

    throw new InvalidPluginExecutionException("type your message here..");

  • MohammadFaheemuddin1600 Profile Picture
    on at
    RE: An unexpected error occurred from ISV code

    Hi

    Could you please provide more details or provide the the code logic you are using.

  • himy10 Profile Picture
    on at
    RE: An unexpected error occurred from ISV code

    Yes, I use that code to show customized code.

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;

    namespace TestPlugin
    {
    public class ImageDemo : IPlugin
    {
    private void ThrowPluginException()
    {
    throw new InvalidPluginExecutionException("The subgrid count is Zero");
    }
    public void Execute(IServiceProvider serviceProvider)

    {

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

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

    // Create service with context of current user
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    //create tracing service
    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

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

    {

    Entity entity = (Entity)context.InputParameters["Target"];
    if (entity.LogicalName.ToLower() != "incident") return;
    try
    {

    Entity preImage = (Entity)context.PreEntityImages["Image"];
    if (preImage.Contains("statecode"))
    {
    if (preImage.GetAttributeValue<OptionSetValue>("statecode").Value == 0)//if Pre image have priority = Low
    {
    if (entity.Contains("statecode") && entity.GetAttributeValue<OptionSetValue>("statecode").Value == 1)
    {
    if (preImage.Contains("new_subcount"))

    {
    Int32 countval = Convert.ToInt32(preImage.GetAttributeValue<Int32>("new_subcount").ToString());

    if (countval == 0)
    {
    ThrowPluginException();
    // throw new InvalidPluginExecutionException("The subgrid count is Zero");

    }


    }
    }
    }
    }
    }
    catch (Exception ex)
    {
    throw new Exception("" + ex.Message);
    }
    }
    }
    }
    }

  • himy10 Profile Picture
    on at
    RE: An unexpected error occurred from ISV code

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans