locked
The 'RetrieveMultiple' method does not support entities of type 'campaignactivityitem' RRS feed

  • Question

  • Hi there,

    While querying the campaignActivityItem, i am getting the error

    The 'RetrieveMultiple' method does not support entities of type 'campaignactivityitem'

    below is the code i am using. What should i do if i need to get this done.

    Thanks!
    QueryExpression query = new QueryExpression();
    query.EntityName = EntityName.campaignactivityitem.ToString();
    ColumnSet cols = new ColumnSet(new string[] { "campaignactivityid" });
    query.ColumnSet = cols;
    LinkEntity listLinkItem = query.AddLink(EntityName.campaignitem.ToString(), "itemid", "entityid", JoinOperator.Inner);
    listLinkItem.LinkCriteria = new FilterExpression();
    ConditionExpression condition = new ConditionExpression("campaignid", ConditionOperator.Equal, CampaignId);
    listLinkItem.LinkCriteria.Conditions.Add(condition);
    
    BusinessEntityCollection oMktList = 
    service.RetrieveMultiple(query);
    Thursday, May 14, 2009 1:31 PM

Answers

  • Hi crmslave,

    yes, this is correct. Because a campaignActivityItem represents an Intersect-Table you have to use the Fetch-method instead of Retrieve or RetrieveMultiple.

    Using Intersect Tables
    http://msdn.microsoft.com/en-us/library/bb928436.aspx

    -----

    When there is a many-to-many relationship between two entities, an intersect table is created. This is true for both system relationships built in to the product as well as custom many-to-many relationships. The name of the table is specified in the IntersectEntityName property in the relationship metadata.

    You can use the intersect tables to refine the result set in the QueryExpression for a RetrieveMultiple query. However, you cannot retrieve the intersect table records directly with the RetrieveMultiple method. To retrieve the records in an intersect table, you must use the Fetch method.

    The following table lists the intersect tables that are used in M:M relationships between system entities.

    Intersect table Entity Entity
    accountleads account lead
    businessunitmap businessunit businessunit
    campaignactivityitem list campaignactivity
    campaignactivityitem salesliterature campaignactivity
    campaignitem campaign campaign
    campaignitem campaign product
    campaignitem list campaign
    campaignitem salesliterature campaign
    competitorproduct competitor product
    competitorsalesliterature competitor salesliterature
    contactinvoices contact invoice
    contactleads contact lead
    contactorders contact salesorder
    contactquotes contact quote
    leadcompetitors lead competitor
    leadproduct lead product
    listmember contact list
    listmember list account
    listmember list lead
    opportunitycompetitors opportunity competitors
    productassociation product product
    productsalesliterature product salesliterature
    productsubstitute product product
    roleprivileges role privilege
    roletemplateprivileges roletemplate privilege
    servicecontractcontacts servicecontract contact
    systemuserlicenses systemuser license
    systemuserroles systemuser role
    teammembership team systemuser

    Example

    The following example shows how to create a query expression by using a link table. The query retrieves all the roles for a user. This is a many-to-many relationship between the system user entity and the role entity. The name of the intersect table is systemuserroles.

    [C#]
    // Set up the CRM Service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.AuthenticationType = 0; 
    token.OrganizationName = "AdventureWorksCycle";
     
    CrmService service = new CrmService();
    service.Url = ""http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    
    // Get the GUID of the current user.
    WhoAmIRequest who = new WhoAmIRequest();
    WhoAmIResponse whoResp = (WhoAmIResponse)service.Execute(who);
    
    Guid userid = whoResp.UserId;
    
    // Create a query expression.
    QueryExpression qe = new QueryExpression();
    qe.EntityName = "role";
    qe.ColumnSet = new AllColumns();
    
    // Create the link entity from role to systemuserroles.
    LinkEntity le = new LinkEntity();
    le.LinkFromEntityName = "role";
    le.LinkFromAttributeName = "roleid";
    le.LinkToEntityName = "systemuserroles";
    le.LinkToAttributeName = "roleid";
    
    LinkEntity le2 = new LinkEntity();
    le2.LinkFromEntityName = "systemuserroles";
    le2.LinkFromAttributeName = "systemuserid";
    le2.LinkToEntityName = "systemuser";
    le2.LinkToAttributeName = "systemuserid";
    
    // Create the condition to test the user ID.
    ConditionExpression ce = new ConditionExpression();
    ce.AttributeName = "systemuserid";
    ce.Operator = ConditionOperator.Equal;
    ce.Values = new object[]{userid};
    
    // Add the condition to the link entity.
    le2.LinkCriteria = new FilterExpression();
    le2.LinkCriteria.Conditions = new ConditionExpression[]{ce};
    
    // Add the from and to links to the query.
    le.LinkEntities = new LinkEntity[]{le2};
    qe.LinkEntities = new LinkEntity[]{le};
    
    // Retrieve the roles and write each one to the console.
    BusinessEntityCollection bec = service.RetrieveMultiple(qe);
    foreach (BusinessEntity e in bec.BusinessEntities)
    {
       role r = (role)e;
       Console.WriteLine(r.name.ToString());
    }

    -----

    Best regards,
    Jürgen


    Jürgen Beck

    Dipl. Kfm./Wirtschaftsinformatik
    MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
    Microsoft Certified Business Management Solutions Professional
    Microsoft Certified CRM Developer
    Microsoft Certified Trainer

    ComBeck IT Services & Business Solutions
    Microsoft Gold Certified Partner
    Microsoft Small Business Specialist

    Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors

    http://www.combeck.de
    Thursday, May 14, 2009 3:27 PM
    Moderator