locked
Execute only when entityreference is not null - how to do this for a plugin?

    Question

  • I am trying to do the code below but it is not working - anyone know why?

    EntityReference cdd = (EntityReference)entity.Attributes["new_case"];

    if (cdd != null)
    {
       //Do code
    }

    Wednesday, December 18, 2013 6:27 PM

Answers

  • You need to check the null condition before:
    try with

    if (entity.Contains("new_case") && entity["new_case"] != null)
    {
    EntityReference cdd = (EntityReference)entity["new_case"];
    // do code
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Wednesday, December 18, 2013 6:31 PM
    • Marked as answer by Sebd.DD Wednesday, December 18, 2013 7:07 PM
    Wednesday, December 18, 2013 6:30 PM

All replies

  • You need to check the null condition before:
    try with

    if (entity.Contains("new_case") && entity["new_case"] != null)
    {
    EntityReference cdd = (EntityReference)entity["new_case"];
    // do code
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Wednesday, December 18, 2013 6:31 PM
    • Marked as answer by Sebd.DD Wednesday, December 18, 2013 7:07 PM
    Wednesday, December 18, 2013 6:30 PM
  • Thank you :)
    Wednesday, December 18, 2013 7:08 PM