locked
CRM 2013 - Issue with Lead firing plugin registered to Contact + Account RRS feed

  • Question

  • Hi

    I have the issue that when I am Qualifying a lead my contact and account plugins are executing which is causing the system to crash because there are custom fields which aren't in the leads form

    I have tried the following to prevent this from happening

    if (context.depth == 1)
      {
        //run code
      }
      else
      {
        return;
      }

    This did nothing so I tried > 1 and that stopped it executing on lead but contact only

    I then moved onto a variety of different options of the following;

    If (context.MessageName.ToLower() == "create" 
        && entity.Contains("originatingleadid") && entity["originatingleadid"] != null)
      {
        return;
      }
      else
      {
        //run code
      }
    

    However this again was unsuccessful, even when I replaces "originatingleadid" to a custom field and inserted data into it it would still try to run the plugin code

    Does anyone have any suggestions as to how to stop this

    My last resort which is one I really don't want to have to do is change Contact and Account plugins to execute on Update which would mean the users going back into the record once created just to execute the plugin

    Thanks, Shaun


    S.Harrison

    Thursday, August 7, 2014 7:51 AM

Answers

  • Hi Shaun ,

    not entity.Contains , change it with entity.Attributes.Contains like below

    If (context.MessageName.ToLower() == "create" 
        && entity.Attributes.Contains("originatingleadid") && entity["originatingleadid"] != null)
      {
        return;
      }
      else
      {
        //run code
      }


    Polat Aydın Crm Software Developer

    Thursday, August 7, 2014 8:01 AM

All replies

  • Hi Shaun ,

    not entity.Contains , change it with entity.Attributes.Contains like below

    If (context.MessageName.ToLower() == "create" 
        && entity.Attributes.Contains("originatingleadid") && entity["originatingleadid"] != null)
      {
        return;
      }
      else
      {
        //run code
      }


    Polat Aydın Crm Software Developer

    Thursday, August 7, 2014 8:01 AM
  • Hi Polat

    Thanks for your advice, I just tried what you suggested, then added entity.Attributes["originatingleadid"] to see if that worked but both were unsuccessful, the only possible reason I can think for this is that even though the Lead Entity is visible CRM is executing as if its under Contact circumstances

    Any further suggestions would be appreciated

    Thanks, Shaun


    S.Harrison

    Thursday, August 7, 2014 8:15 AM
  • Hi Shaun,

    When you qualify your lead to Account or Contact , In Account or Contact Pre/Post Create Plugin entity.Attributes.Contains("originatingleadid")  comes true. There is no way to work unsuccessful.Be sure for that


    Polat Aydın Crm Software Developer

    Thursday, August 7, 2014 8:19 AM
  • Hi Polat

    Feel like such a fool! I had originatingcaseid not leadid as that what was present in lead fields. Completely didn't notice that I had it wrong this whole time. Thanks for your help, works fine now!

    Thanks, Shaun


    S.Harrison

    Thursday, August 7, 2014 8:25 AM