Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin is not getting triggered when creating automatic Case from Incoming Emails

Posted on by Microsoft Employee

While creating automatic Case from Incoming email by using Automatic Record creation or update rule, need to call plugin to call external service, this plugin is working fine when creating case from Web but not from external email.

Am i missing any step here? Any suggestion?

Thanks,

Nishant

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Yeah. Thanks for your help, Alex!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hi Alex,

    Thanks a lot for the help, I really appreciate it

    Thanks,

    Nishant

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hey Nishant,

     I just realized, btw, that you don't need that depth condition at all.. it's an "oncreate" plugin - there can be no recursion there ("Depth" makes total sense for the updates.. where you can call another update while in the update already.. but there can be no such situation for the "create".. so you can just get rid of it)

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hi Nishant,

     that's the thing - you just need to figure out what the depth is for the rules..

     Or you might alter those conditions slightly:

    - Create a new field on the case

    - Populate it from the rule only (don't even expose it on the form)

     In your plugin, change that Depth condition this way:

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

    {

    Entity caseRecord = (Entity)context.InputParameters["Target"] ;

    if (context.Depth > 1 && (!caseRecord.Contains(<YOUR NEW FIELD>) || caseRecord[YOUR NEW FIELD] == null))

    return;

    caseRecord[YOUR_NEW_FIELD] = null;//so the condition above does not work the second time

    ..Rest of your code..

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hi Alex,

    I have tried it and it worked but without context.Depth property, 

    Code:

    public class ExtAPICallOnCrete :IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    var serviceb = serviceFactory.CreateOrganizationService(context.UserId);

    if (context.Depth > 2)
    return;
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
    {
    Entity caseRecord = (Entity)context.InputParameters["Target"] ;
    try
    {
    if (caseRecord.LogicalName == "incident")
    {
    StringBuilder builder = new StringBuilder();
    builder.Append(RandomString(4, true));
    builder.Append(RandomNumber(1000, 9999));
    builder.Append(RandomString(2, false));
    caseRecord.Attributes["new_caseid"] = builder.ToString();
    caseRecord.Attributes["new_duplicate"] = true;
    //return builder.ToString();

    }

    }
    catch (Exception ex)
    {
    throw new InvalidPluginExecutionException("Plugin has encountered erro", ex);
    tracingService.Trace(ex.ToString());
    }
    }
    }

    private string RandomString(int size, bool lowerCase)
    {
    StringBuilder builder = new StringBuilder();
    Random random = new Random();
    char ch;
    for (int i = 0; i < size; i++)
    {
    ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
    builder.Append(ch);
    }
    if (lowerCase)
    return builder.ToString().ToLower();
    return builder.ToString();
    }

    private int RandomNumber(int min, int max)
    {
    Random random = new Random();
    return random.Next(min, max);
    }
    }

     

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hey guys,

       I think it's completely unfair to Dynamics to basically say that it's all powered by magic.. So, take it or leave it, but here are some test results:

    Plugin code:

    7178.Rule.PNG

    Plugin step registration:

    registration.PNG

    Email-to-case conversion through the UI:

    ConvertedCase.PNG

     

    And for the automated rule..

     

    Here is the rule:

    7178.Rule.PNG

    Here is the case:

    RuleCase.PNG

     

    As expected, it all works.. works as expected.. not sure how else I can twist those two words to make the point.

    I'm pretty certain the devil is in the details, as usual, so we just need to see that plugin code to figure it out.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    That's by design as I mentioned (since 2011 as what I had experienced), it is not under the create case message when you convert email to case.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hi Melving,

    Custom workflow did work, but still i am amazed why plugin is not triggering for this,

    I will keep looking for definite resolution, please let me know if you get anything on this

    Thanks,

    Nishant

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hi Nishant,

     any chance we could see the code?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin is not getting triggered when creating automatic Case from Incoming Emails

    Hi Melvin,

    Email to case create anyhow creating Case so It should trigger Plugin

    Thanks,

    Nishant  

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans