locked
CRM 2011 - How to find record entity type using its Guid RRS feed

  • Question

  • In my plugin I have a record guid (it is not the main entity the plugin is registered on). I need to know what type of entity it is.

    Spceficically, my plugin is registered for Connection entity and the Guid that I have in the plugin could be Contact, Opportunity or Incident type.

    I would like the code in the plugin to execute if the entity type of the Guid is Contact.

    How do I achieve this?

    Thank you very much for your help in advance.

    Monday, August 5, 2013 5:14 PM

Answers

  • In your plugin during the pre-event, if the request also contains a condition for the record1objecttypecode then you could inspect that to determine if it is a contact or not.  If it doesn't then you'll need to execute a Retrieve Multiple using either a QueryByAttribute or QueryExpression to determine if that value is a contact or not.  - Also, your plugin should verify the query is actually a QueryExpression and not a QueryByAttribute.
    Alternatively, in the post event you can look at the output parameters for the response's business entity collection and examine the type there, as long as it suits your needs.

    Hope it helps, good luck.

    Monday, August 5, 2013 6:25 PM

All replies

  • Hi,

    I hope you are getting guid from lookup field ??, then you can use LogicalName property from entity reference


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, August 5, 2013 5:38 PM
    Moderator
  • Hi Mahender,

    No, I am not getting that from a lookup field.

    I am getting that from where clause of a query expression. To be specific (record1id of the connection entity). So this could be a contact type, opportunity type, etc.

    Monday, August 5, 2013 5:43 PM
  • could you share you code ??

    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, August 5, 2013 5:49 PM
    Moderator
  • Here it is:

    if (_context.InputParameters.Contains("Query"))

    {

      QueryExpression query = (QueryExpression)_context.InputParameters["Query"];

      Guid contactid = Guid.Empty;

      var contact = query.Criteris.Conditions.ElementAt(1).Values;

      contactid = (Guid) contact[0];

      // rest of the code here - want to execute this code if and only if the contactid above is contact record type

      the plugin is registered on RetrieveMultiple message of the Connection entity. The above contactid could be opportunityid, etc. As specified I would live to execute the plugin code if the

      record1id above extracted from ElementAt(1).Values is a contact type record.

     

    Monday, August 5, 2013 6:06 PM
  • In your plugin during the pre-event, if the request also contains a condition for the record1objecttypecode then you could inspect that to determine if it is a contact or not.  If it doesn't then you'll need to execute a Retrieve Multiple using either a QueryByAttribute or QueryExpression to determine if that value is a contact or not.  - Also, your plugin should verify the query is actually a QueryExpression and not a QueryByAttribute.
    Alternatively, in the post event you can look at the output parameters for the response's business entity collection and examine the type there, as long as it suits your needs.

    Hope it helps, good luck.

    Monday, August 5, 2013 6:25 PM
  • Thank you very much Daniel for your inputs...

    The request does not contain a condition for record1objecttypecode. I can do a RetrieveMultiple easily and pass in 3 parameters (i.e. "contact", record1id, and an attribute). If the function comes back successfully, it means it has found the contact record and I am good.

    The only think I am afraid of is that if I do this function call and pass in lets say an opportunityid and ask retrievemultiple to find that guid in contact which obviously should fail, do I get an exception error or function retruns with null?

    If the RetrieveMultiple retruns with null, I can check for that and not execute the code. If it throws an exception, then that is not a good solution.

    I can try this and see what happens. Have you tried this before?

    Thanks again.

    Monday, August 5, 2013 6:38 PM
  • Daniel,

    After reading your comments again, I noticed that as you specified above I could do a RetrieveMultiple using a queryexpression in which case the Retrieve multiple should not throw any exception and simply returns nothing or one. So I belive this should work in my situation. I will give it a try shortly.

    Thank you very much again.

    Homayoun

    Monday, August 5, 2013 6:52 PM
  • Your very welcome.  And yes, your correct the response would contain an empty collection if nothing was found so you would be able to determine that it wasn't a contact in that case.
    Monday, August 12, 2013 5:35 PM