6

I am trying to get the native lookup window to open up and when the value is selected needs to populate a hidden field.

I am able to call the lookup function, but when i select the value nothing happens, the lookup window doesnt close and value is not posted into the hidden field.

function showLookup(ctrlID,objKeyPrefix) 
    { 
        openLookup("/_ui/common/data/LookupPage?lkfm=ConvertwithInputs:pbmconvertInput:pbformmconvertInput&lknm="+ ctrlID +"&lktp="+objKeyPrefix,500);           
     }

<apex:inputText id="vField_AccountName_lkid" value="{!s.selectedAccount}"/>           
<apex:image url="/s.gif" alt="Lookup (New Window)" styleClass="lookupIcon" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onclick="javascript:showLookup('ConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:' + jQuery(this).closest('tr').prevAll('tr').length + ':vField_AccountName','001')" title="Lookup (New Window)"/>

The url generated in the lookup used by the above window is

https://c.na15.visual.force.com/_ui/common/data/LookupPage?lkfm=ConvertwithInputs:pbmconvertInput:pbformmconvertInput&lknm=ConvertwithInputs:pbmconvertInput:pbformmconvertInput:pbsmconvertInput:pbspbtable:0:vField_AccountName&lktp=001

The url when you click on search result is

https://c.na15.visual.force.com/_ui/common/data/LookupResultsFrame?lktp=001&lknm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3AvField_AccountName&lkfm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput#

To test the urls i also had a standard lookup and the url generated is

https://c.na15.visual.force.com/_ui/common/data/LookupPage?lkfm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput&lknm=massConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3Aj_id7&lktp=001&lksrch=

The link on the search result for standard lookup is

https://c.na15.visual.force.com/_ui/common/data/LookupResultsFrame?lktp=001&lknm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput%3ApbsmconvertInput%3Apbspbtable%3A0%3Aj_id7&lksrch=&lkfm=ConvertwithInputs%3ApbmconvertInput%3ApbformmconvertInput#

Where does the closing of lookup window happen?

Any pointers on what is happening while clicking of search result, where does the closing and assigning of value happen?

Thanks

  • 1
    The official answer is, of course, that you should not try to use the built-in libraries, because they could change in a future release that breaks your page(s). Personally, I'd build my own, just so I know how it works. – sfdcfox Sep 11 '13 at 11:28
3

As sfdcfox stated, not a good idea to use the SF libraries.

Here is a link to a blog post by Jeff D. that works well for roll your own Salesforce lookup popup window:

It’s a handy little button that pops up whenever you need to search for related records. It does a pretty good job but it has some serious drawbacks:

  1. It’s virtually impossible to modify your search criteria. What if you want your users to do some crazy search based upon custom logic or search a field that is not typically available? Sorry… you are out of luck. Not possible.
  2. It’s terrible for creating new records. Let’s say that a user searches for a specific related record and it (absolutely) doesn’t exist. To create the new record they need to close the lookup window, navigate to the tab to create the new related record, create the new record, then go back to the original record they were either editing or creating, pop up the lookup window again and find their newly created record. Wow! That’s a lot of work.
  3. “Quick Create” is evil! You can enable the “Quick Create” option for an entire org but don’t do it! It displays, by default, on the tab home pages for leads, accounts, contacts, forecasts, and opportunities! The major problems are that you can only create new records for these 5 objects (what about the other ones!?), you can’t customize the fields on the page and validation rules don’t fire (can you say, “bad data”).

http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/

1

I experienced this issue when trying to call the native Lookup window through a custom button as part of some work with Campaigns. I had the behavior set to URL, and this was causing the lookup window to open, but never close whenever a value was selected.

The URL in my custom button was set to: /_ui/common/data/LookupPage?lkpr=00vf0000004Sh6f&lktp=701&enableScopes=1&addToCampaign=1&isCMClone=1

To get around this, it appears that Salesforce accepts an openLookup JavaScript function.

Therefore, I changed the expected behavior to JavaScript on my custom button, and put in the following code, which then allowed the Lookup Window to close whenever a value was selected.

openLookup('/_ui/common/data/LookupPage?lkpr=00vf0000004Sh6f&lktp=701&enableScopes=1&addToCampaign=1&isCMClone=1',670,'1','');

(This button applies to Campaigns/Campaign Members, so you likely don't need all the parameters.)

0

have you checked your Javascript console, I think that the onlick for the searchResult fails

<a href="#" class=" dataCell " onclick="top.window.opener.lookupPick('editPage','acc3_lkid','acc3','','001i0000008NgRR','SW_Sample Customer','null','')">SW_Sample Customer</a>

And I think thats because the lookupPick and functios called from it try to access one of the other lookup related fields

<input type="hidden" name="acc3_lkid" id="acc3_lkid" value="000000000000000">
<input type="hidden" name="acc3_lkold" id="acc3_lkold" value="null">
<input type="hidden" name="acc3_lktp" id="acc3_lktp" value="001">
<input type="hidden" name="acc3_lspf" id="acc3_lspf" value="0">
<input type="hidden" name="acc3_lspfsub" id="acc3_lspfsub" value="0">
<input type="hidden" name="acc3_mod" id="acc3_mod" value="0">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.