locked
How do in c # RRS feed

  • Question

  • How do in c # ? How as reference a field.

     

    if (crmForm.all.new_name.DataValue == "Milk")

    {

    crmForm.all.new_completname = "Milk Stve";

    }

    Wednesday, October 24, 2007 4:41 PM

Answers

  • The crmForm object only exists in the CRM client form, and hence can only be accessed through client java script. C# can only be used in server code.

     

    What are you trying to achieve, and what type of assembly (e.g. web appplication, callout assembly, console application) are you writing with C#

     

    Wednesday, October 24, 2007 6:34 PM
    Moderator
  • Hi Luiz,

     

    You can look in the "server programming guide" in the sdk: http://msdn2.microsoft.com/en-us/library/aa682866.aspx

     

    Some code examples are given there as well including this one:

    // Set up the CRM Service.
    CrmService service = new CrmService();
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create the contact object.
    contact contact = new contact();

    // Create the properties of 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 CRM.
    Guid contactGuid = service.Create(contact);

     

     

    As you can see, you will always need a entity to work with. In your code you can either create one (see example) or retrieve one (for instance with callouts). Take some time to read through the pages of the server programming guide in the SDK to get started.

     

    Hope this helps,

     

    Ronald Lemmen

    http://www.ronaldlemmen.com

    Friday, October 26, 2007 5:47 PM
    Moderator
  • If you want to write code which runs when the form loads, the only way to do this in CRM 3.0 is to add the code in the onload event of the form, and this code has to be written in Java Script, not C#

    Saturday, October 27, 2007 12:20 PM
    Moderator

All replies

  • The crmForm object only exists in the CRM client form, and hence can only be accessed through client java script. C# can only be used in server code.

     

    What are you trying to achieve, and what type of assembly (e.g. web appplication, callout assembly, console application) are you writing with C#

     

    Wednesday, October 24, 2007 6:34 PM
    Moderator
  • hi,

     

    but, how can I using this (e.g. web appplication, callout assembly, console application), I want a example to understand more

     

    Thank You.

    Friday, October 26, 2007 3:58 PM
  • Hi Luiz,

     

    You can look in the "server programming guide" in the sdk: http://msdn2.microsoft.com/en-us/library/aa682866.aspx

     

    Some code examples are given there as well including this one:

    // Set up the CRM Service.
    CrmService service = new CrmService();
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create the contact object.
    contact contact = new contact();

    // Create the properties of 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 CRM.
    Guid contactGuid = service.Create(contact);

     

     

    As you can see, you will always need a entity to work with. In your code you can either create one (see example) or retrieve one (for instance with callouts). Take some time to read through the pages of the server programming guide in the SDK to get started.

     

    Hope this helps,

     

    Ronald Lemmen

    http://www.ronaldlemmen.com

    Friday, October 26, 2007 5:47 PM
    Moderator
  • Hi Ronald,

     

    Thank you. This example I already did, I would like for example that when loads the form of contact would have a field load or if a picklist value = 1 then  field "X" have to receive "test".

     

     

    Friday, October 26, 2007 6:32 PM
  • If you want to write code which runs when the form loads, the only way to do this in CRM 3.0 is to add the code in the onload event of the form, and this code has to be written in Java Script, not C#

    Saturday, October 27, 2007 12:20 PM
    Moderator
  • Hi,
    Thank You. In javascript I did, but then c# is not? Only in javascript ?
     
    For example I have in c #:

    Calculate age from the date of birth. In javascript I did

     

    Monday, October 29, 2007 11:58 AM
  • Hi Luiz,

     

    I'd like to summarize what David and I have been trying to explain in the previous posts.

     

    MS Dynamics CRM allows you to do both JavaScript and C# coding. The difference is that the C# coding must be server side and the JavaScript code must be client side. That means that any changes you would like to happen on the client, you will need to do in JavaScript code. If you want something to happen on the server side, you will need C# code. Things like showing and hiding fields based on an attribute of an entity are things that must be done in the client. Calculation of the age baed on the birth date and storing it in another attribute is something that i would do on the server.

     

    I hope this makes you understand a bit more about when to use client side javascript or serverside c# codes.

     

    Kind regards,

     

    Ronald Lemmen

     

    Monday, November 5, 2007 11:50 AM
    Moderator
  • Ok. Thanks for attention. I understood, what I wanted to know is how to do this in C #, because I do not know. I am a newcomer in CRm

     

    Thanks,

    Monday, November 5, 2007 4:23 PM