locked
CrmService in 2011 SDK RRS feed

  • Question

  • I am trying to convert a CRM 4 plugin to CRM 2011. The plugin has a helper class which has functions in it.

    I started from this code:

     

    public static BusinessEntity[] getPunchcardAccounts(CrmService service)
        {
          QueryByAttribute query = new QueryByAttribute();
    
          query.ColumnSet = new AllColumns();
          query.EntityName = EntityName.account.ToString();
          query.Attributes = new String[] { "fg_ispunchcard" };
          query.Values = new String[] { "True" };
    
          BusinessEntityCollection results = service.RetrieveMultiple(query);
          return results.BusinessEntities;
        }



    and converted it to this:

     

    public static Entity[] getPunchcardAccounts(CrmService service)
      {
       QueryByAttribute query = new QueryByAttribute();
    
       query.ColumnSet = new ColumnSet(true);
       query.EntityName = Account.EntityLogicalName.ToString();
       query.Attributes.Add("fg_ispunchcard");
       query.Values.AddRange("True");
    
       EntityCollection results = service.RetrieveMultiple(query);
       return results.Entities.ToArray();
      }
    

     


    I have the following references in my CRM 2011 plugin code:

    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;

    The CRM 4 plugin has only a web service reference.

    The 2011 code compiles well except for the CrmService type. It cannot find it in the SDK. When I try to reference the web service and remove the SDK references, it finds the CrmService type but some of the code is not supported, for example:

    query.Values.AddRange("True");
    

    What do you think I should do to fix this problem?

     

    Thank you

     


    Friday, August 5, 2011 5:02 PM

Answers

  • You should use IOrganizationService instead of CrmService. And to rewrite your query you can write it as follows:

    QueryByAttribute query = new QueryByAttribute(Account.EntityLogicalName);
    query.ColumnSet = new ColumnSet(true);
    query.AddAttributeValue("fg_ispunchcard", "True");
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    • Marked as answer by KatRiketa Friday, August 5, 2011 5:25 PM
    Friday, August 5, 2011 5:15 PM
    Moderator