+ Start a Discussion
GoForceGoGoForceGo 

How do I create a lookup field in S-control

I want to create an S-control form where one of the fields is supposed to be a lookup field - e.g I want to define a field called "Contact" and be able to have the lookup icon.
When clicked it should show all salesforce contacts and when one is selected, populate it.

How do I do it?

sfdcfoxsfdcfox
This is wickedly annoying to do, but here goes...
 
Code:
<html>
 <head>
  <title>...</title>
  <script src="/static/022207/js/functions.js"></script>
  <link rel="stylesheet" href="/dCSS/Theme2/en/common.css">
  <script>
  // all your code will go here.
  </script>
 </head>
 <body>
  ...
<form name="theForm" id="theForm">
  ...
<tr><td class="labelCol">
<label for="contact">Contact</label>
<input type="hidden" name="contact_lkid" id="contact_lkid">
<input type="hidden" name="contact_lkoid" id="contact_lkoid">
<input type="hidden" name="contact_lktp" id="contact_lktp" value="003">
<input type="hidden" name="contact_lspf" id="contact_lspf" value="0">
<input type="hidden" name="contact_mod" id="contact_mod" value="0">
</td>
<td class="dataCol">
 <span class="lookupinput">
  <input type="text" id="contact" name="contact"
   onchange="document.getElementById('contact_lkid').value='';document.getElementById('contact_mod').value='1';">
  <a title="Related To Contact Lookup (New Window)"
   href="javascript:openLookup('/_ui/common/data/LookupPage?lknm=contact&lkfm=theForm&lkrf=&sn=1&lktp='+document.getElementById('contact_lktp').value,670,document.getElementById('contact_mod').value,'&lksrch='+escapeUTF(document.getElementById('contact').value),'maxw')"
   onclick="setLastMousePosition(event)"
   id="whtbtn"><img src="/s.gif" alt="Related To Contact Lookup (New Window)" class="lookupPopup"></a></span></td></tr>
  ...
 </form>
 </body>
</html>

 
And... yes, that's for a single lookup, and I don't even have all the required elements to make it look "Salesforce-like", just close enough to give you a text box and a magnifying glass. This whole magick code could break at any time; VisualForce is the only "guaranteed" method of not breaking lookup elements inbetween releases. So, enjoy the code, and have fun.
 
Edit: Fixed code that would have likely produced incorrect results. The "src" button is getting better though.


Message Edited by sfdcfox on 12-24-2007 03:48 PM
sfdcfoxsfdcfox
The &colon; in the above code should probably be an actual colon, but it's encoding it for me, probably a XSS feature.
hudinihudini
Hi there,
what if i wanted to do the same thing - but in an s-control accessed by a button on a page. For example  - I would like to pre-populate the contact related lookup on the opportunity page.
so i created a button accessing an s-control, and my s-control looks like this

<script language="JavaScript">

function redirect() {

parent.frames.location.replace("/006/e?retURL=%2F{!Contact.Id}&RecordType=012200000004ZSp&conid={!Contact.Id}&

00N20000000vVQR={!Contact.FirstName}+{!Contact.LastName}&CF00N20000000vVQR_lkid={!Contact.Id}& CF00N20000000vVQR_lkoid={!Contact.Id}& CF00N20000000vVQR_lkold={!Contact.Id}& &CF00N20000000vVQR_lktp={!Contact.Id}& CF00N20000000vVQR_lspf= {!Contact.Id} & CF00N20000000vVQR_mod={!Contact.Id}&CF00N20000000vVQR_lkwgt={!Contact.Id}&accid={!Account.Id}&opp3={!Contact.FirstName} {!Contact.LastName} Follow Up- {!Today}&opp9={!Today}")

}

redirect();

</script>

it is still not populating though - any ideas?
I have pre-populated a contact lookup on a custom related object - does this have to do with the opportunity role setup?
thanks!
Hudi
GoForceGoGoForceGo
Thanks sfdcfox.

Does you know when VisualForce might GA?