locked
set lookup value on text field RRS feed

  • Question

  • I have entity in award(custom)  having lookup field contact related to contact entity.

    I want to set the value of lookup in to new_name (text) field.

    I am using Following code, but it is not working. 

    Please any one can Help.

     

    var con_lookup = crmForm.all.new_contact.DataValue;

     

    if(con_lookup != null)

    {

         var con =  con_lookup[0].name;

         if(con != null)

         {

                crmForm.all.new_name.DataValue =    con;

        }

     

    }

    Monday, October 18, 2010 10:26 AM

Answers

  • As this very simple code does not appear to be working, I have to wonder how the code is executed.  Is the code attached to the OnChange event of the "new_contact" field?  If so, is that event actually enabled at this time?  (There is a checkbox for that.)  Also, have you successfully published the customizations?  Without publishing, the code will not execute.  While Rhett's recommendation is sound, and through Marco and Julio show you different ways to do practically exactly what you're already doing (in different, abbreviated ways), your code should suffice for the job that you require it to do.  Therefore, I believe that the issue is how the code is called and the deployment of it.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    • Marked as answer by Jim Glass Jr Tuesday, October 19, 2010 7:23 PM
    Monday, October 18, 2010 5:44 PM
    Moderator

All replies

  • You do not need this condition

      if(con != null)

    as yo uhave already checked that the lookup contains a value here

    var con_lookup = crmForm.all.new_contact.DataValue;

     if(con_lookup != null)


    MSCRM Bing'd - http://bingsoft.wordpress.com

    Check out the CRM 4 to CRM 2011 JavaScript Converter Tool
    Monday, October 18, 2010 10:36 AM
    Moderator
  • Have you tried to debug page using IE Toolbar?

     

    Running (for example) :

     

      crmForm.all.new_quotationno.DataValue = crmForm.all.new_resellerid.DataValue[0].name;
    

    populates a text field with the name displayed in the lookup.

     

     

    Monday, October 18, 2010 1:00 PM
  • Have you published your code?? have you got any error??? Is your lookup field new_contact or new_contactid???
    As Marco says, you only need set the DataValue of new_name with the name of the lookup... and your code ought to something like this:

    crmForm.all.new_name.DataValue=crmForm.all.new_contact.DataValue[0].name;


    Julio
    Monday, October 18, 2010 5:28 PM
  • As this very simple code does not appear to be working, I have to wonder how the code is executed.  Is the code attached to the OnChange event of the "new_contact" field?  If so, is that event actually enabled at this time?  (There is a checkbox for that.)  Also, have you successfully published the customizations?  Without publishing, the code will not execute.  While Rhett's recommendation is sound, and through Marco and Julio show you different ways to do practically exactly what you're already doing (in different, abbreviated ways), your code should suffice for the job that you require it to do.  Therefore, I believe that the issue is how the code is called and the deployment of it.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    • Marked as answer by Jim Glass Jr Tuesday, October 19, 2010 7:23 PM
    Monday, October 18, 2010 5:44 PM
    Moderator