function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
deepak kumar 13deepak kumar 13 

How to return value selected record from custom lookup into visualforce page

Hi Below is my VF page i have 3 lookup fields based on lookup field i am opening new custom lookup page. And selected records should get populated into lookup field. But the problem is if i select any record it navigates to new tab and opens record detail page. and i am using javascript to get selected values.Please suggest me where i am doing mistake in javascript.


Below is my vf page

<apex:page standardController="Target_Members__c" extensions="NewTargetMember">
<apex:sectionHeader title="Target Member Edit" subtitle="New Target Member"/>
<script type="text/javascript">
var objectName ;
var accId;
function openemailPopup(obj,objname,objlabel)
{
currConColumn = obj;
objectName=objname;
var likeString = (obj.getElementsByTagName('input')[0]).value;
var url ;
var additionalFilter=''; if(objname=='Account'){
additionalFilter='Email__c !=null and Status__c=\'Active\' and HasEmailOptOut__c!=true and Mail_Opt_Out__c!=true and Fax_Opt_Out__c!=true and Do_Not_Call__c!=true and Debarred__c != true and (Type=\'Clinical\'or Type=\'Hospital\')';
url = '{!$Page.CustomLookUpPopUpPage}'+"?likestring="+likeString+"&obj="+objname+"&objlb="+objlabel+"&additionalFilter="+additionalFilter;
}
if(objname=='Contact'){
additionalFilter='Accountid!=null and Email!=null and Status__c=\'Active\' and HasOptedOutOfEmail!=true and DoNotCall!=true and Mail_Opt_Out__c!=true and HasOptedOutOfFax!=true and Debarred__c!=true and (Type__c=\'Investigator\' OR Type__c=\'Physician\' OR Type__c =\'Physician Investigator\') ';
url = '{!$Page.CustomLookUpPopUpPage}'+"?likestring="+likeString+"&obj="+objname+"&objlb="+objlabel+"&additionalFilter="+additionalFilter;
}
if(objname=='CTMax__Patient__c') {
additionalFilter='Email__c!=null and Opt_In__c!=true and Do_Not_Call__c!=true and Fax_Opt_Out__c!=true and Mail_Opt_Out__c!=true'; url = '{!$Page.CustomLookUpPopUpPage}'+"?likestring="+likeString+"&obj="+objname+"&objlb="+objlabel+"&additionalFilter="+additionalFilter;
}
openWind(url);
return false;
}
function openWind(URL) {
curPopupWindow = window.open(URL, "_blank","width=600, height=400,dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=1", false);
}
function setSelectedDocumentDetails(etId,etName) {
// alert('-etId--'+etId);alert('-etName--'+etName);
var inputArr = currConColumn.getElementsByTagName('input');//alert('inputArr--------'+inputArr);
inputArr[0].value = etName; inputArr[1].value = etId; //s = s.substring(0, s.length - 4) // alert(inputArr[1].value); inputArr[1].value = inputArr[1].value.substring(0, inputArr[1].value.length - 3); // alert(inputArr[1].value);
if(curPopupWindow != null) {
curPopupWindow.close();
}
currConColumn = null;
return false;
} </script>
<apex:form id="theForm">
<apex:actionFunction name="callme" action="{!setfieldvals}" reRender="theForm" status="sts"/>
<apex:pageMessages id="msg"/>
<apex:actionStatus id="sts" style="align:center;" >
<apex:facet name="start" >
<apex:image value="/img/loading.gif" title="Processing..."/>
</apex:facet>
<apex:facet name="stop">
</apex:facet>
</apex:actionStatus>
<apex:pageBlock Title="Target Member Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!gosave}" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageblocksection title="Information">
<apex:inputfield value="{!target.Multi_Channel_Recruitment__c}"/>
<!--------------------------Field Set Goes Here--------------------------------> <apex:repeat value="{!$ObjectType.Target_Members__c.FieldSets.TargetMemberPage}" var="fs">
<apex:inputField value="{!target[fs]}" required="{!OR(fs.Required,fs.DBRequired)}"/>
</apex:repeat>
</apex:pageblocksection>
<!-----------------------------Target Institution-------------------------------->
<apex:pageblocksection title="Internal Target Member" columns="2">
<apex:pageblocksectionitem >
<apex:outputLabel value="{!$ObjectType.Target_Members__c.fields.Target_Institution__c.label}"/>
<apex:outputpanel id="p1">
<apex:inputtext value="{!accounText}">
<apex:actionSupport event="onchange" action="{!setfieldvals}" reRender="theForm" status="sts"/>
</apex:inputtext>
<a id="cclookup" href ="" style="cursor: pointer" onClick="javascript:return openemailPopup(this.parentNode,'Account')">
<img src="/s.gif" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" /></a>
<apex:inputhidden value="{!accId}" id="hid">
</apex:inputhidden>
</apex:outputpanel>
</apex:pageblocksectionitem>
<!--<apex:inputField value="{!target.Target_Institution__c}"/>-->
<!-----------------------------Target Patient--------------------------------->
<apex:pageblocksectionitem >
<apex:outputLabel value="{!$ObjectType.Target_Members__c.fields.Target_Patient__c.label}"/>
<apex:outputpanel id="p2">
<apex:inputtext value="{!patientText}">
<apex:actionSupport event="onchange" action="{!setfieldvals}" reRender="theForm" status="sts"/>
</apex:inputtext>
<a id="cclookup" href ="" style="cursor: pointer" onClick="javascript:return openemailPopup(this.parentNode,'CTMax__Patient__c','Patient')"> <img src="/s.gif" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" /></a>
<apex:inputhidden value="{!patId}" id="hid1">
</apex:inputhidden>
</apex:outputpanel>
</apex:pageblocksectionitem>
<!-----------------------------Target Physician--------------------------------->
<apex:pageblocksectionitem >
<apex:outputLabel value="{!$ObjectType.Target_Members__c.fields.Target_Physicians__c.label}"/>
<apex:outputpanel id="p3">
<apex:inputtext value="{!contactText}">
<apex:actionSupport event="onchange" action="{!setfieldvals}" reRender="theForm" status="sts"/>
</apex:inputtext> <a id="cclookup" href ="" style="cursor: pointer" onClick="javascript:return openemailPopup(this.parentNode,'Contact')">
<img src="/s.gif" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" /></a>
<apex:inputhidden value="{!conId}" id="hid2">
</apex:inputhidden>
</apex:outputpanel>
</apex:pageblocksectionitem>
<apex:inputField value="{!target.Target_Clinical_Site__c}"/>
</apex:pageblocksection>
<!-----------------------------Field Set Goes here--------------------------------->
<apex:pageblocksection title="Prospect Information">
<apex:repeat value="{!$ObjectType.Target_Members__c.FieldSets.ProspectTargetMemPage}" var="fd">
<apex:inputField value="{!target[fd]}" required="{!OR(fd.Required,fd.DBRequired)}"/>
</apex:repeat>
</apex:pageblocksection>
</apex:pageBlock>
</apex:form>
</apex:page>


Thanks,
Deepak
Rahul SharmaRahul Sharma
You should reuse the standard openLookup function which salesforce provides. See jeff's blog (http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/) for more details.