Using a Custom Page for a Lookup

From LongJump Support Wiki

About Custom Lookup Pages

When you select the Custom Page option, a dropdown lists all pages available in the application. The page chosen from that list will present Lookup choices to the user.

Considerations

The following platform features are not supported. They must be handled in the JSP page:

  • Lookup Selection Criteria
  • Post Selection Javascript
  • Auto completion. (For a platform Lookup, typing the first 3 characters into the Lookup field automatically generates a list of matching records.)

Available Parameters

Parameter Description
keyword Input: The value the user entered into the Lookup field, if any, before clicking the Lookup icon. That value can be used to refine the query that searches for records to display to the user.
object_id Output: Object identifier. For example, "ACCOUNT", or "qzb342rty234" for a custom object. (Object name will not work.)
target_field Output: The name of the field that will store the ID of the selected record.
target_name_field Output: The name of the field that will store the record name. (See note below.)

Notepad.png

Note: The record name is a textual identifier that represents a selected record. It is the concatenation of fields designated as the "Record Identifier" in the Object's Record Locators. The content for this field must accompany the record_id when data is stored in the Lookup field, and it must follow this format:

{field1Value} - {field2Value} - ...

where field1Value, field2Value, etc. are in the same order as the fields specified for the Object's Record Identifier in Record Locators.

Retrieving Object Records

The JSP page needs to:

a. Fetch records using AJAX and REST
b. Present them to the user
c. Let the user make a choice
Learn more: REST API Retrieve a Record

Selecting a Record for a Lookup in the Custom JSP Window

When the custom page is displayed, it was launched by a Form in the platform. This example inserts the user's selection into that form, and closes the popup window the page is displayed in.

JavaScript Code

if (window.opener.document.mainForm.<%=target_field%>)
   window.opener.document.mainForm.<%=target_field%>.value = {Record Id};  

if (window.opener.document.mainForm.<%=target_name_field%>)
   window.opener.document.mainForm.<%=target_name_field%>.value = {Record Identifier};
   // Format: "{fieldValue} - {fieldValue} - ..."  E.g "Jones - Bobby"
   
//Close the popup window
window.close();

Selecting a Record for a Multi Object Lookup in the Custom JSP Window

This code is similar to the previous example. The only difference is in the format of the record ID for a multi-object lookup field.

JavaScript Code

if (window.opener.document.mainForm.<%=target_field%>)
  window.opener.document.mainForm.<%=target_field%>.value = {Multi Object Record Id};  
  // Format: "{Object Id}:{Record ID}"  E.g "ACCOUNT:1234567"

if (window.opener.document.mainForm.<%=target_name_field%>)
  window.opener.document.mainForm.<%=target_name_field%>.value = {Record Identifier};
  // Format: "{fieldValue} - {fieldValue} - ..."  E.g "Jones - Bobby"
   
//Close the popup window
window.close();