to create a look up Programmatically, first its best to find a lookup of the entity you want to make. lets take a look up of
cases for example...
It is best to find or create a relationship on an entity to the case entity and create a lookup on the form.
for this demonstration, the lookup schema is named 'new_caseid'
so after this lookup is created, i created a textbox on the form called 'new_test'.
then i saved the following code in an onchange event on the new_test textbox:
var asdf = crmForm.all.new_caseid_d.innerHTML crmForm.all.new_test.DataValue = asdf;
now when i change the value of the textbox, the html that creates the lookup will be inserted into the textbox for me to
use later. It is wise to do this for when the lookup = null and when the lookup has a value in it. Save both of the html
recovered from these values into Notepad for later.
Now you have the html for the lookup you want to create.
so to create the lookup on any form now, just create a textbox ( i created 'new_caseurl') here is the code i made to turn the texbox into a lookup:
//return form box to modified html crmForm.all.new_caseurl_d.innerHTML = html; var htmlmod = '<TABLE class=lu style='TABLE-LAYOUT: fixed' cellSpacing=0 cellPadding=0 width='100%'><TBODY><TR><TD><DIV
class=lu><SPAN class=lui onclick=gotocaseweb() data='' otypename='incident' otype='112'
oid='{8D018DF0-9CF9-DB11-AE85-0019B9BD8D31}'><IMG class=lui src='http://crm.davidsprecher.com/_imgs/ico_16_112.gif'>'
+casenumber+'<B style='PADDING-LEFT: 4px'></B></SPAN></DIV></TD><TD style='TEXT-ALIGN: right' width=25><IMG class=lu
id=new_caseid title='Click to select a value for Case.' tabIndex=1010 src='/_imgs/btn_off_lookup.gif' req='0'
defaulttype='0' lookupstyle='single' lookupbrowse='0' lookuptypeIcons='/_imgs/ico_16_112.gif'
lookuptypenames='incident:112' lookuptypes='112'></TD></TR></TBODY></TABLE>'
crmForm.all.new_caseurl_d.innerHTML = htmlmod;
|