Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:48:16+00:00 2026-06-09T10:48:16+00:00

I am writing crm2011 plugin in Email entity with Send Message of Pre_operation. What

  • 0

I am writing crm2011 plugin in “Email” entity with “Send” Message of Pre_operation. What i want to do is when i click “Send” button in email entity, I do the necessary checking before send. If the checking is not correct, I want to prevent and stop the sending email and show “the alert message” and stop the second plugin(this plugin send email and create the associated entity to convert “Case”). Please give me some suggestion for that plugin?
Should i use pre-Validation stage or Pre_operation state? And how can I return false to stop plugin.

  public void Execute(IServiceProvider serviceProvider)
    {
        try
        {
            string message = null;
            _serviceProvider = serviceProvider;
            _context = (IPluginExecutionContext)
                                         serviceProvider.GetService(typeof(IPluginExecutionContext));

            _serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            _currentUser = _context.UserId;
            message = _context.MessageName.ToLower();
            if (message == "send")
            {
                if (_context.InputParameters != null && _context.InputParameters.Contains("EmailId"))
                {
                    object objEmailId = _context.InputParameters["EmailId"];
                    if (objEmailId != null)
                    {
                        _emailId = new Guid(objEmailId.ToString());
                        FindEmailInfo();
                        if (_email != null)
                        {
                            if (_email.Attributes.Contains("description") && _email.Attributes["description"] != null)//Email descritpion is not null
                            {
                                string emaildescription = StripHTML();

                                //Find KB Article prefix no in system config entity
                                serviceguideprefix = "ServiceGuidesPrefix";
                                QueryByAttribute query = new QueryByAttribute("ppp_systemconfig");
                                query.ColumnSet = new ColumnSet(true);
                                query.AddAttributeValue(sysconfig_name, serviceguideprefix);
                                EntityCollection sysconfig = _service.RetrieveMultiple(query);
                                if (sysconfig.Entities.Count > 0)
                                {
                                    Entity e = sysconfig.Entities[0];
                                    if (e.Attributes.Contains("ppp_value"))
                                    {
                                        ppp_value = e.Attributes["ppp_value"].ToString();
                                    }
                                }
                                if (ppp_value != null && ppp_value != string.Empty)
                                {
                                    //var matches = Regex.Matches(emaildescription, @"KBA-\d*-\w*").Cast<Match>().ToArray();
                                    var matches = Regex.Matches(emaildescription, ppp_value + @"-\d*-\w*").Cast<Match>().ToArray();
                                    //ReadKBNo(emaildescription);
                                    foreach (Match kbnumber in matches)
                                    {
                                        EntityCollection kbarticlecol = FindKBArticleIds(kbnumber.ToString());
                                        if (kbarticlecol.Entities.Count > 0)
                                        {
                                            Entity kbariticle = kbarticlecol.Entities[0];
                                            if (kbariticle.Attributes.Contains("mom_internalkm"))
                                            {
                                                bool internalserviceguide = (bool)kbariticle.Attributes["mom_internalkm"];
                                                if (internalserviceguide) found = true;
                                                else found = false;
                                            }
                                            else found = false;
                                        }
                                    }
                                }
                                if (found)
                                {
                                    //-----
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw new InvalidPluginExecutionException(ex.Message, ex);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:48:19+00:00Added an answer on June 9, 2026 at 10:48 am

    Well stopping the plugin is dead easy you just throw InvalidPluginException, the message you give it will be shown to the user in a alert window. You will have to do this on the pre of the send. In this case I don’t think it will matter if its pre-validation or pre-operation.

    Edit:

    Yes, you should throw an InvalidPluginException even if no exception has happened in code. I accept this isnt what we would normally do, but its the way its meant to work. Msdn has more details: http://msdn.microsoft.com/en-us/library/gg334685.aspx

    So for example the code would look like:

    public void Execute(IServiceProvider serviceProvider)
    {
        try    
        {
            //This is where we validate the email send
            if(emailIsOkay)
            {
                //Do something
            }
            else if(emailIsNotOkay)
            {
                //Throw and exception that will stop the plugin and the message will be shown to the user (if its synchronous)
                throw new InvalidPluginExecutionException("Hello user, your email is not correct!!");
            }
        }
        catch (InvalidPluginExecutionException invalid)
        {
            //We dont to catch exception for InvalidPluginExecution, so just throw them on
            throw; 
        }
        catch (Exception ex)
        {
            //This exception catches if something goes wrong in the code, or some other process.
            throw new InvalidPluginExecutionException(ex.Message, ex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing my first C# application...never touched the language before and not much of a
I am writing a plugin (my first) for CRM2011 which needs to pull some
Writing a plugin for [top-secret] (not really :P) and I decided that one best
Writing some drag&drop code, I'd like to cancel the click events in my mouseup
Writing an iPhone app in which I want to save the user the grief
writing in QT and QErrorMessage by default has checkbox saying: Show this message again
Writing a shell script and I want to do something like this: cp myfile.ext
I'm writing a stand-alone service (not a plug-in, in the strictest sense) to periodically
Writing a recursive function, I want one fn that executes when the list has
Writing a class, how do I implement foo.send(item) ? __iter__ allows iterating over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.