0

I am working on visual force pages for my custom object Request_for_System_Change__c.

There is a Yes/No picklist called Request_Priority__c

When this is Yes I want to show the field Reason_for_High_priority__c so the user can explain why the request is high priority.

Here below is the code:

<apex:inputField value="{!Request_for_System_Change__c.Request_Priority__c }">  
<apex:actionSupport event="onchange"    rerender="MyPanel"/>                                        
</apex:inputField>

<apex:outputPanel id="MyPanel">
<apex:outputPanel rendered="{!IF(NOT(ISBLANK(Request_for_System_Change__c.Request_Priority__c)) 
&& ISPICKVALRequest_for_System_Change__c.Request_Priority__c, 'High'),true,false)}">

<apex:outputLabel value="reason for High Priority: "/>
<apex:inputField value="{!Request_for_System_Change__c.Reason_for_High_priority__c }"/>
</apex:outputPanel>
</apex:outputPanel>

But I am getting an error when saving:

Incorrect parameter type for function 'ISPICKVAL()'. Expected Picklist, received Text

so what am I doing wrong?

NOTE: I have taken the above code from the answer given by mast0r here

3
  • 1
    I think there's a syntax issue in the code above, because the ISPICKVAL does not have an open bracket. Also, can you paste the controller code, please? Is the name of your property 'Request_for_System_Change__c'? That's a bit confusing
    – mkorman
    Jan 5, 2016 at 16:07
  • 1
    Try: ISPICKVAL(Request_for_System_Change__c.Request_Priority__c, 'High') (assuming that the field Request_Priority__c is a picklist field) Jan 5, 2016 at 16:11
  • is there anything wrong in my code that would cause the input field Reason_for_High_Priority to show regardless of the value in the picklist? Jan 5, 2016 at 16:29

1 Answer 1

1

When you handle a picklist value on a Visualforce page using the

!{Record__c.Field__c}

merge style syntax, since about 2009, it actually delivers the value as a string, not a picklist "object", the object is only delivered to the inputField/outputField widgets.

So all you need to do is:

rendered="{! NOT(ISBLANK(Request_for_System_Change__c.Request_Priority__c)) 
&& Request_for_System_Change__c.Request_Priority__c == 'High'}"

I have a feeling that can be simplified somehow too.. looks like a lot of logic, but that - at the very least - will solve the ISPICKVAL problem.

Edit: I'm afraid I don't know why this is.. in double-checking this I thought I had finally cracked it to be using the different logical operators (like NOT and && side by side in a formula) but that didn't seem to change it in the end.

Edit2: I was right, I think you could express this easier as:

rendered="{! Request_for_System_Change__c.Request_Priority__c != null 
          && Request_for_System_Change__c.Request_Priority__c == 'High'}"
8
  • I had to change it to rendered="{!IF(NOT(ISBLANK(Request_for_System_Change__c.Request_Priority__c) && Request_for_System_Change__c.Request_Priority__c == 'High'), true, false)} as the IF() function threw an invalid arguments exception...but thanks, I will try that Jan 5, 2016 at 16:25
  • 1
    oh, crickey, yes sorry. I don't think you need the "if" function - I thought I'd removed it (one of my edits was to rebalance my brackets, I must have copied it back in!) try whats in my answer now? ah wait... "now" Jan 5, 2016 at 16:27
  • 1
    check my second edit.. I reckon that would be how I would do it Jan 5, 2016 at 16:30
  • is there anything wrong in my code that would cause the input field Reason_for_High_Priority to never be displayed even when "High" is selected in the [I]priority[/i] picklist? Jan 5, 2016 at 16:30
  • 1
    Two things: There's a typo in the first code block (!{ instead of {!). Second, the rendered formula can simply be: {!Request_for_System_Change__c.Request_Priority__c='High'}. If it's equal to High, it is not null. Also, Visualforce uses formula syntax, meaning = is appropriate for comparison.
    – sfdcfox
    Jan 5, 2016 at 20:52

You must log in to answer this question.

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