5

Can I access the WhatId search scope (polymorphic picklist) in Visualforce as a separate element. See attachment to get the full picture.

enter image description here

2 Answers 2

1

enter image description here

I am sure this is not the best way but this is my way of solving this issue.

Criteria : The whatid is the first lookup on the page, if you have multiple lookups .

I am hiding the first lookup value on the page. You need to modify the openlookup() method related to the onclick event related to the custom lookup to pickup the picklist value.

<apex:page standardController="task">
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"/>
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js"/>
<script type="text/javascript">
$j = jQuery.noConflict();
$j( document ).ready(function() {
  $j('.lookupInput').first().hide();
});

</script>
<apex:form >
<apex:inputField value="{!task.whatId}"/>
<apex:inputField value="{!task.ownerid}"/>
</apex:form>
</apex:page>
0
1

First Build out picklist in controller class

public String selectedItem { get; set; } { selectedItem = ''; }

    public List<SelectOption> options { get; private set; }
    {
        options = new List<SelectOption>();
        //options.add(new SelectOption('', '')); 
        options.add(new SelectOption('Account', 'Account'));
        options.add(new SelectOption('Deal__c', 'Deal'));
    }

Then use this in the VFP

  <apex:selectList style="width:150px, {!Style}" value="{!SelectedItem}" size="1" id="selectRecordType">
    <apex:selectOptions value="{!Options}"/>
</apex:selectList> 

 <apex:inputText style="{!Style}" styleClass="auto{!randomJsIden}" value="{!cacheField}" />
    <apex:outputPanel id="hiddenPanel">
        <apex:inputText value="{!targetField}" id="hiddenField"
            styleClass="hiddenField{!randomJsIden}" style="display:none"/>
    </apex:outputPanel>
    <script>v2{!randomJsIden} = new autocompleteV2{!randomJsIden}({});</script>
</apex:component>

Finally use jquery to access the selected option

       var recordType= j$('[id*=selectRecordType] option:selected').text();


      alert('Query data for:'+recordType);

       Visualforce.remoting.Manager.invokeAction(
               //  '{!$RemoteAction.AutoCompleteV2_Con.getData}','{!sObjVal}','{!labelField}','{!valueField}',query.term,
                 '{!$RemoteAction.AutoCompleteV2_Con.getData}',recordType,'{!labelField}','{!valueField}',query.term,
                 function(result, event){

                     //if success
                     if(event.status){ 
                         var data = {results: []}
                         data.results = result;                            
                         query.callback( data);                           
                     }
                     else{
                          alert('Invalid Field/Object API Name : '+event.message);

                     }

                 }, 
                  {escape: true}
            );
        }  

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .