locked
How to take a lookup field in visual studio RRS feed

  • Question

  • Hi,

    I am developing a webpage to insert a new incident directly from our website  using crm sdk.
    i need a little help how to search the existing account (from the CRM accounts) and insert it in the case field customer.
    eSharing.com
    Wednesday, February 4, 2009 9:22 PM

Answers

  • Hi ,
        Download the MS CRM v4.0 SDK. if you haven't already.

    there is sample code in the help file on how to search for records and how to create records.

    I've pasted some sample code from the SDK to get you started.
    The following example demonstrates the use of the Retrieve method.

    [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 object that indicates the properties to be retrieved.
    ColumnSet cols = new ColumnSet();

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

    // contactGuid is the GUID of the record being retrieved.
    Guid contactGuid = new Guid("4D507FFE-ED25-447B-80DE-00AE3EB18B84");

    // Retrieve the contact.
    // The EntityName indicates the EntityType of the object being retrieved.
    contact contact = (contact)service.Retrieve(EntityName.contact.ToString(), contactGuid, cols);


    Example
    The following example demonstrates the use of the Create method.

    // 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 contact object.
    contact contact = new contact();

    // Create the properties for the contact object.
    contact.firstname = "Jesper";
    contact.lastname = "Aaberg";
    contact.address1_line1 = "23 Market St.";
    contact.address1_city = "Sammamish";
    contact.address1_stateorprovince = "MT";
    contact.address1_postalcode = "99999";
    contact.donotbulkemail = new CrmBoolean();
    contact.donotbulkemail.Value = true;

    // Create the contact in Microsoft Dynamics CRM.
    Guid contactGuid = service.Create(contact);

    • Proposed as answer by Hassan Hussain Thursday, February 5, 2009 11:31 AM
    • Marked as answer by eSharing Sunday, February 15, 2009 11:26 PM
    Thursday, February 5, 2009 11:31 AM

All replies

  • Hi ,
        Download the MS CRM v4.0 SDK. if you haven't already.

    there is sample code in the help file on how to search for records and how to create records.

    I've pasted some sample code from the SDK to get you started.
    The following example demonstrates the use of the Retrieve method.

    [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 object that indicates the properties to be retrieved.
    ColumnSet cols = new ColumnSet();

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

    // contactGuid is the GUID of the record being retrieved.
    Guid contactGuid = new Guid("4D507FFE-ED25-447B-80DE-00AE3EB18B84");

    // Retrieve the contact.
    // The EntityName indicates the EntityType of the object being retrieved.
    contact contact = (contact)service.Retrieve(EntityName.contact.ToString(), contactGuid, cols);


    Example
    The following example demonstrates the use of the Create method.

    // 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 contact object.
    contact contact = new contact();

    // Create the properties for the contact object.
    contact.firstname = "Jesper";
    contact.lastname = "Aaberg";
    contact.address1_line1 = "23 Market St.";
    contact.address1_city = "Sammamish";
    contact.address1_stateorprovince = "MT";
    contact.address1_postalcode = "99999";
    contact.donotbulkemail = new CrmBoolean();
    contact.donotbulkemail.Value = true;

    // Create the contact in Microsoft Dynamics CRM.
    Guid contactGuid = service.Create(contact);

    • Proposed as answer by Hassan Hussain Thursday, February 5, 2009 11:31 AM
    • Marked as answer by eSharing Sunday, February 15, 2009 11:26 PM
    Thursday, February 5, 2009 11:31 AM
  •  Hi Hussain,

     

    thanks for your reply,

    I will explain what i need:

    i retreived the Unique identifier of the contact. I need to insert this id in the incident table using sdk

    means newincident.customerid = Guid("5d476cd7-f1a1-dd11-8c32-000c298e3dbc") is it right like this?

     

     

     


    eSharing.com
    Friday, February 6, 2009 9:22 AM