get values from entity attributes with javascript


  • Hi,

    I have created a custom entity Tax with attribute like name and taxRate. And now i like to get the value from taxRate to do some further calculations. For Example I choose motor vehicle tax( i.e. 0.7 ) from a lookup and i automatically get the taxRate in a custom field.

    Is it possible to get the values via Javascript?


    Tuesday, November 25, 2008 9:30 AM

All replies

  • On the New_MotorVehicleTax.Onchange() event, you may use: crmForm.all.new_taxRate.DataValue to get the taxRate value.




    Tuesday, November 25, 2008 9:45 AM
  • Thx for your quick reply. But this doesn't solve my problem. Maybe i can precise my post...

    I have a Entity "Tax" and it has the attributes  id, name and a custom attribute taxrate. So i have already created some sample data like motor vehicle tax, county tax. with specifc taxrates

    Now i like to use the taxrates in another Form. If i choose "Tax" the lookUp shows me
    motor vehicle tax, county tax.
    By selecting one Data i like to have the specific taxrate shown in a custom field. So i can do some further calculations.

    i.e. i choose county tax ----> 0.2 will be the taxrate. Which i need for further calculations. This schould be show in a custom field.


    @Jim i really like your blog i've been reading it since weeks and it helped me a lot, thx for the blog Wink

    Tuesday, November 25, 2008 10:51 AM
  • Hey.. here is the script for you to get the Taxrate on change of Taxid lookup.


    Kindly note the following information which is used in this script.

    Please change the same with your CRM attribute information.

          Tax entity name: asu_tax

          Tax lookup name: asu_taxid

          Tax rate name: asu_taxrate




    var lookupItem = new Array;

    // Get the lookup for the Taxid attribute on the account form.

    lookupItem = crmForm.all.asu_taxid.DataValue;

    // If there is data in the field, show it in a series of alerts.

    if (lookupItem[0] != null)


    // Display the GUID of the lookup.

    var taxid = lookupItem[0].id;


    //Prepare variables for a contact to retrieve.

    var authenticationHeader = GenerateAuthenticationHeader();

    //Prepare the SOAP message.

    var xml = "<?xml version='1.0' encoding='utf-8'?>"+

    "<soap:Envelope xmlnsTongue Tiedoap=''"+

    " xmlns:xsi=''"+

    " xmlns:xsd=''>"+



    "<Retrieve xmlns=''>"+


    "<id>"+ taxid +"</id>"+

    "<columnSet xmlns:q1='' xsi:type='q1:ColumnSet'>"+








    //Prepare the xmlHttpObject and send the request.

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");

    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);


    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    xHReq.setRequestHeader("Content-Length", xml.length);


    //Capture the result.

    var resultXml = xHReq.responseXML;

    //Check for errors.

    var errorCount = resultXml.selectNodes('//error').length;

    if (errorCount != 0)


    var msg = resultXml.selectSingleNode('//description').nodeTypedValue;



    //Display the retrieved value.





    //Set this value to required attribute.


    Please let me know if this solution works for you.



    Tuesday, November 25, 2008 2:57 PM
  • thank you very much, but where do i have to put the code?
    into OnChange() of the lookUp field or in the Onchange of the Custom TaxrateTest field?

    I tried both but i didn't get any response? no change.

    Tuesday, November 25, 2008 3:37 PM

    You have to put this script on Onchange() of the custom lookup field. Also, please ensure that you have enabled the same event.

    Wednesday, November 26, 2008 5:10 AM
  • After i choose something in the lookup, it ask for my user and password. I tried to log in but after 3 times i recieve an error message. Why does this happen?
    Wednesday, November 26, 2008 2:31 PM
  • Hello!

    I still facing this Problem, i don't know why it asking me for the credentials...
    Any links for this Problem would be helpful.
    Wednesday, December 03, 2008 10:28 AM
  •  Amit Choudhari wrote:

    Dear Amit,


    I am a bit new to CRM customization. I have an issue which is the cause to a lot of hiccups in my customisation. Can u tell me how to change the attribute value in a lookup. For Eg In the account section when I select the "parent account" lookup it always selects the "Account name", instead my client wants account number to be appearing in the lookup. Is it possible to change the attribute? The lookup always pulls the primary attribute of the entity. I guess I have to write a onload script to change the attribute. Can u pls help me with it?


    Saturday, December 27, 2008 12:13 AM