locked
Retrieve attribute from different entities RRS feed

  • Question

  • Hi everyone,

    I have a doubt about how to retrieve in a query using the web services attribute from different entities. The idea is to retrieve the contacts in a marketing list, and also the name of the marketing list.

    Is this possible?

    Thanks
    Tuesday, October 6, 2009 3:45 PM

Answers

  • Since the relationship between a contact and a marketing list is many to many (N:N) you have to query the middle table that is created between them.

    The object in your code you need to be using is called "listmember", this is the name of the relationship entity object between contact and marketing list.

    These 2 attributes are the ones you need to use.
    "entityid" - GUID of the entity object, in your case contact.
    "memberlistid" - GUID of the marketing list.

    So query the listmember entity with the guid of the marketinglist into the "memberlistid" attribute.

    This should return a list of objects (BusinessEntities) that you can loop through looking at the "entityid" if you need to query the crm for the contacts.
    Use the memberlistid to query the crm for a marketinglist if you need to find the name.

    Can check the CRM database tables, there should be a table called "listmemberbase" there you can compare guids from a marketing list and a contact etc.
    • Marked as answer by Jim Glass Jr Tuesday, October 6, 2009 6:06 PM
    Tuesday, October 6, 2009 5:27 PM

All replies

  • Since the relationship between a contact and a marketing list is many to many (N:N) you have to query the middle table that is created between them.

    The object in your code you need to be using is called "listmember", this is the name of the relationship entity object between contact and marketing list.

    These 2 attributes are the ones you need to use.
    "entityid" - GUID of the entity object, in your case contact.
    "memberlistid" - GUID of the marketing list.

    So query the listmember entity with the guid of the marketinglist into the "memberlistid" attribute.

    This should return a list of objects (BusinessEntities) that you can loop through looking at the "entityid" if you need to query the crm for the contacts.
    Use the memberlistid to query the crm for a marketinglist if you need to find the name.

    Can check the CRM database tables, there should be a table called "listmemberbase" there you can compare guids from a marketing list and a contact etc.
    • Marked as answer by Jim Glass Jr Tuesday, October 6, 2009 6:06 PM
    Tuesday, October 6, 2009 5:27 PM
  • Ok thanks, I see so the idea is that it is no possible to retrieve all this information with only one query, isn't it?.
    Wednesday, October 7, 2009 7:42 AM
  • Hey Halldor,
    just to increase my knowledge, how do we get the information about middle table in N:N relationship context?
    Wednesday, October 7, 2009 10:10 AM
  • Hey Halldor,
    just to increase my knowledge, how do we get the information about middle table in N:N relationship context?

    If you go into the entity (Settings->Customization->YourEntity) click the N:N Relationship and double click the relationship you intend to find, this should open a window and under the Relationship Definition you will see 2 names "Relationship Entity Name" will contain the name of the new middle table, however you will have to add "base" to the back of it to find it in the database itself.
    So if the name is "new_myentitytoaccount" then "new_myentitytoaccount" will be the name of the entity so to speak and the name of the table in the database will be "new_myentitytoaccountbase" but there will also be a view with the name "new_myentitytoaccount".

    Hope this helps!
    Wednesday, October 7, 2009 10:20 AM
  • Ok thanks, I see so the idea is that it is no possible to retrieve all this information with only one query, isn't it?.

    To be honest I am not sure on the one query thing, however querying the CRM system a few times should not be a problem for you, you would need 3 queries if I understand your problem correct.

    1 query for the memberlist to get the guids of the contacts you need.
    1 query to get the Marketing list name.
    1 query to get the contacts (you can add an array of guids to send a single query to the CRM system for the contacts)

    These queries should not slow down your system much more than having this done in 1 query.

    Hope this answer helps.

    Wednesday, October 7, 2009 10:25 AM
  • Regarding fetching multiple entities you could check this thread regarding LinkEntity, Marius is having problems with other things but the LinkEntity code should give you some insight into multiple entity query.

    http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/3f9e70fa-494e-4eff-9f16-5d38678ca561

    I havent used it myself so not sure what data you can get back, but its worth checking out.

    Friday, October 9, 2009 2:32 PM