Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Exception don't show in message window

Posted on by 10

Hello all.

I have a problem: I try to throw exception in my pre-create plugin, but it don't show in message window after save and go only in trace journal, and in journal it is unhandled.

Example of code:

public class PreUpdatePepperValidationPlugin : IPlugin
    {
        void IPlugin.Execute(IServiceProvider serviceProvider)
        {
            try
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                var pepper = (Entity)context.InputParameters["Target"];
                var i = 0;
                
                if (pepper.Attributes.Contains("new_breeder_name"))
                {
                    if (string.IsNullOrWhiteSpace(pepper.GetAttributeValue("new_breeder_name")))
                    {
                        throw new InvalidPluginExecutionException("messageA");
                    }
                }

                if (pepper.Attributes.Contains("new_breeder_surname"))
                {
                    if (string.IsNullOrWhiteSpace(pepper.GetAttributeValue("new_breeder_surname")))
                    {
                        throw new InvalidPluginExecutionException("message b");
                    }
                }

                i = 0;
                
                var img = context.PreEntityImages["UpdatePepperPreImage"];

                
                if (pepper.Attributes.Contains("new_spice"))
                {
                    var new_spice = pepper.GetAttributeValue("new_spice");
                    
                    if (new_spice < 0)
                    {
                        throw new InvalidPluginExecutionException("less zero ex");
                    }
                    if (new_spice < img.GetAttributeValue("new_spice"))
                    {
                        throw new InvalidPluginExecutionException("less pre ex");
                    }
                }
            }
            catch (InvalidPluginExecutionException e)
            {
                throw e;
            }

            catch (Exception e)
            {
                throw e;
            }
            

            
        }
    }

P. S. Sorry for my English.

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Exception don't show in message window

    First of all, your condition is working but not showing a desire pop-up message. Am I correct?

    Thanks

    Regards,

    Abdul Wahab

  • Rakesh90 Profile Picture
    Rakesh90 200 on at
    RE: Exception don't show in message window

    What do you mean by 'on this'. Where is it not working? Your first post mentions that the code is not working in pre-create plugin.

  • Kirill Semenov Profile Picture
    Kirill Semenov 10 on at
    RE: Exception don't show in message window

    Not working.

    Interesting that the same code correctly works on PreCreate plugin, but on this - don't.

    Anyway thanks for spent time.

  • Suggested answer
    Rakesh90 Profile Picture
    Rakesh90 200 on at
    RE: Exception don't show in message window

    OK. Disable any pop-up blockers on your browser and try again.
    Sometimes the pop-up blocker on your browser might also stop showing error pop-ups. 

    If this answers your question please mark my answer as verified

  • Kirill Semenov Profile Picture
    Kirill Semenov 10 on at
    RE: Exception don't show in message window

    My plugin is synchronous, I have already checked this.

  • Suggested answer
    Rakesh90 Profile Picture
    Rakesh90 200 on at
    RE: Exception don't show in message window

    Please check if the plugin is registered on Synchronous operation and NOT Asynchronous.

    If this answers your question, please mark this answer as Verified!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans