Populate field using onchange event. RRS feed

  • Question

  • Hello


    I know there are many responses to this very basic question, however none of them are very clear and I have tried many of them to no avail. I am sure it is something very simple that I am missing so please answer as if I have no programming experience at all.


    I am using CRM 4.0


    I created a new Entity called SCR


    I have created an N:1 relationship for the SCR entity with the Account entity


    I have created two custom fields in the Attributes of the SCR entity





    There are two mappings of the N:1 relationship for the SCR entity with the Account entity


    Source = Account Entity field = accountid    -      Target = SCR Entity field = new_accountid

    Source = Account Entity field = address1_line1    -      Target = SCR Entity field = new_street1


    On the SCR Entity Form I added a field for the new_accountid that looks up the Account name from the Account Lookup View and a text field for the new_street1 that I want to have populated when the Account is selected in the new_accountid field.


    I added the field address1_line1 to the Account Lookup View


    I added the following code to the SCR Entity Form's OnLoad event


    Code Snippet

    function OnCrmPageLoad()
       crmForm.all.new_accountid.attachEvent( "onafterselect" , OnAccountSelected );
    function OnAccountSelected()
       // Get Address data from lookup view

       var lookupValues = crmForm.all.new_accountid.items[0].keyValues;
       var address1 = lookupValues.address1_line1.value; 
       // Populate Address fields
       crmForm.all.new_street1.DataValue = address1;




    I did save all the changes and Publish the changes


    However, when I create a new SCR, the new_street1 field does not populate with the value of the Account's address1_line1 field when I select an Account from the Account lookup.


    Could someone walk me through what I have done wrong?


    Thank you very much.


    Allan Browning

    Saturday, April 26, 2008 5:02 AM


  • Hello Everyone.


    I have now learned that what I was wanting to do above cannot be accomplished in the manner I was attempting.


    You can ONLY populate a field on any form using the simple onchange event IF the field you are pulling data from is also on the same form. This would be most useful if you wanted to populate a field on a different tab of the same form so that you did not have to enter the data twice.


    There are programmatic ways to do this but they are very involved for the novice user.


    I have since found using a Work Flow is the best and easiest way to accomplish what I was attempting. It works very well.


    Thanks you.


    Allan Browning.

    Sunday, April 27, 2008 5:57 PM