locked
AttachEvent on a lookup field RRS feed

  • Question

  • Hi

    I have succesfully implemented context sensitive help on each field. When user presses F2 on a field, the help message shows in a new window.

    I have created a custom entity in CRM, where user can create context sensitive help message, in relation to an entity name  and a field name.

    In javascript I get the entityname and field name and calls Help.aspx that uses the entity name and field id to access database, in order to get the related help message.

    It works for all fields, except the LookUp fields where event.srcElement.id sadly is undefined :-(

    Any one knows why and is there a workaround ????

    In every entity formular onLoad I include the external javascript file and attach the event:   

    crmForm.attachEvent("onkeyup", GetContextHelp);    
     

    This folowing code is located in en external javascript file:
    function GetContextHelp
    {

        if (event.keyCode == 113)
        {    

          docId = event.srcElement.id; 
     
         var url = '/ISV/ContextHelp/Help.aspx?Entity=' + crmForm.ObjectTypeName + '&Field=' + docId
         var objHelp = window.open(url, 'Hjaelpetekst', 'width=440, height=170, toolbar=0, location=0, status=0, menubar=0, resizable=0');
         objHelp.focus();
    }

     

     

    Thursday, October 7, 2010 6:47 AM

Answers

  • As yes.sudhanshu indicates, the Lookup's "control" exists almost entirely within the image component of the field.  The behavior and rendering of the Lookup control, however, is much more complicated.  There is a peculiar DOM structure to the control.  It's basically a table with two cells:

    A table cell that holds 3 peers: 1.) a DIV containing one SPAN element for displaying each currently held value; 2.) a label element; and, 3.) an input field.  The last two are hidden.  The input field has an "id" value/attribute; but the first two do not.  When you select the field, you are actually selecting the DIV element (and/or any of its SPAN subordinates).  Those do not contain "id" DOM values/attributes.

    Another cell that holds the IMG element, which has an "id" value/attribute of the field's schema name in CRM.

    Here's the raw HTML of the whole control (with no values represented by SPANS in the DIV):

    <TABLE style="TABLE-LAYOUT: fixed" class=ms-crm-Lookup cellSpacing=0 cellPadding=0 width="100%"><TBODY>
    <TR>
    <TD>
    <DIV class=ms-crm-Lookup tabIndex=1151 ime-mode="auto"></DIV><LABEL class=ms-crm-Hidden-NoBehavior for=territoryid_ledit>Territory</LABEL><INPUT id=territoryid_ledit class=ms-crm-Hidden-NoBehavior tabIndex=1150 maxLength=1000 ime-mode="auto"></TD>
    <TD class=Lookup_RenderButton_td width=25><IMG style="IME-MODE: auto" id=territoryid class=ms-crm-Lookup title="Click to select a value for Territory." alt="Click to select a value for Territory." src="/_imgs/btn_off_lookup.gif" req="0" resolveemailaddress="0" showproperty="1" autoresolve="1" defaulttype="0" lookupstyle="single" lookupbrowse="1" lookupclass="Territory" lookuptypeIcons="/_imgs/ico_16_2013.gif" lookuptypenames="territory:2013" lookuptypes="2013"><A title="Click to select a value for Territory." tabIndex=-1 onclick=previousSibling.click(); href="#"></A></TD></TR></TBODY></TABLE>
    

    You'll need to have your script perform some hunting if the srcElement.id is undefined.  Use this tidbit to help:

    if (typeof(event.srcElement.id) == "undefined")) {
     // Then you may have a Lookup
    }
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, October 7, 2010 11:31 PM
    Moderator

All replies

  • the look up is a combination of a text field and an image . if you will see the structure of the way its getting rendered you can see the difference between the tesxt box and lookup field.

    may be for that its not giving.

     

     


    yes.sudhanshu

    http://bproud2banindian.blogspot.com
    http://ms-crm-2011-beta.blogspot.com
    Thursday, October 7, 2010 7:32 AM
  • As yes.sudhanshu indicates, the Lookup's "control" exists almost entirely within the image component of the field.  The behavior and rendering of the Lookup control, however, is much more complicated.  There is a peculiar DOM structure to the control.  It's basically a table with two cells:

    A table cell that holds 3 peers: 1.) a DIV containing one SPAN element for displaying each currently held value; 2.) a label element; and, 3.) an input field.  The last two are hidden.  The input field has an "id" value/attribute; but the first two do not.  When you select the field, you are actually selecting the DIV element (and/or any of its SPAN subordinates).  Those do not contain "id" DOM values/attributes.

    Another cell that holds the IMG element, which has an "id" value/attribute of the field's schema name in CRM.

    Here's the raw HTML of the whole control (with no values represented by SPANS in the DIV):

    <TABLE style="TABLE-LAYOUT: fixed" class=ms-crm-Lookup cellSpacing=0 cellPadding=0 width="100%"><TBODY>
    <TR>
    <TD>
    <DIV class=ms-crm-Lookup tabIndex=1151 ime-mode="auto"></DIV><LABEL class=ms-crm-Hidden-NoBehavior for=territoryid_ledit>Territory</LABEL><INPUT id=territoryid_ledit class=ms-crm-Hidden-NoBehavior tabIndex=1150 maxLength=1000 ime-mode="auto"></TD>
    <TD class=Lookup_RenderButton_td width=25><IMG style="IME-MODE: auto" id=territoryid class=ms-crm-Lookup title="Click to select a value for Territory." alt="Click to select a value for Territory." src="/_imgs/btn_off_lookup.gif" req="0" resolveemailaddress="0" showproperty="1" autoresolve="1" defaulttype="0" lookupstyle="single" lookupbrowse="1" lookupclass="Territory" lookuptypeIcons="/_imgs/ico_16_2013.gif" lookuptypenames="territory:2013" lookuptypes="2013"><A title="Click to select a value for Territory." tabIndex=-1 onclick=previousSibling.click(); href="#"></A></TD></TR></TBODY></TABLE>
    

    You'll need to have your script perform some hunting if the srcElement.id is undefined.  Use this tidbit to help:

    if (typeof(event.srcElement.id) == "undefined")) {
     // Then you may have a Lookup
    }
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Thursday, October 7, 2010 11:31 PM
    Moderator
  • yes, you need to dig to the original id as specified by David.
    yes.sudhanshu

    http://bproud2banindian.blogspot.com
    http://ms-crm-2011-beta.blogspot.com
    Friday, October 8, 2010 6:26 AM