locked
Fetch lead window application RRS feed

  • Question

  • Tell me the c#.net Windows application code to Fetch lead 

    I m working on RTITSL organisation.

    How to fetch lead in windows application using c#.net
    Monday, October 26, 2009 12:39 PM

Answers

  • 1) create a web reference to MS CRM Webservice
    i.e.
    http://<servername>:<port>/mscrmservices/2007/crmservice.asmx

    2)  Use this code to reterive multiple leads

    C#]
    // Set up the CRM service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    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;

    // Create the column set that indicates the fields to be retrieved.
    ColumnSet cols = new ColumnSet();

    // Set the properties of the column set.
    cols.Attributes = new string [] {"name", "accountid"};

    // Create the ConditionExpression.
    ConditionExpression condition = new ConditionExpression();

    // Set the condition for the retrieval to be when the city in the account's address is Sammamish.
    condition.AttributeName = "address1_city";
    condition.Operator = ConditionOperator.Like;
    condition.Values = new string [] {"Sammamish"};

    // Create the FilterExpression.
    FilterExpression filter = new FilterExpression();

    // Set the properties of the filter.
    filter.FilterOperator = LogicalOperator.And;
    filter.Conditions = new ConditionExpression[] {condition};

    // Create the QueryExpression object.
    QueryExpression query = new QueryExpression();

    // Set the properties of the QueryExpression object.
    query.EntityName = EntityName.lead.ToString();
    query.ColumnSet = cols;
    query.Criteria = filter;

    // Create the request object.
    RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();

    // Set the properties of the request object.
    retrieve.Query = query;
         
    // Execute the request.
    RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);

    or if you want to reterive a single lead, use this code

    // Set up the CRM service.
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    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;

    // Create the column set object that indicates the fields to be retrieved.
    ColumnSet cols = new ColumnSet();

    // Set the properties of the column set.
    cols.Attributes = new string [] {"name"};

    // Create the target object for the request.
    TargetRetrieveLead target = new TargetRetrieveLead();

    // Set the properties of the target object.
    // EntityId is the GUID of the record being retrieved.
    target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");

    // Create the request object.
    RetrieveRequest retrieve = new RetrieveRequest();

    // Set the properties of the request object.
    retrieve.Target = target;
    retrieve.ColumnSet = cols;

    // Execute the request.
    RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);

    Monday, October 26, 2009 12:47 PM