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)

An unexpected error occurred from ISV code

(0) ShareShare
ReportReport
Posted on by 134

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

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

    Hi

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

  • MohammadFaheemuddin1600 Profile Picture
    15 on at

    Hi

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

  • himy10 Profile Picture
    134 on at

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

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