0

I am trying to create an If statement that will output the date of TimeclockStartDate__c if it has a value and to not output anything if the field is left bank. I am getting an error: "Syntax Error" What am I doing wrong? It is an issue with the IF-statement.

            <p> Completed Trainings: </p>
            <ol style= "indent" margin= "10px 0px">
                        <li type="circle"> <u>Core Training</u> </li>
                        <li type="circle"> Staff Training </li>
                        {!IF(ISNULL({!relatedTo.TimeclockStartDate__c}), NULL,<li type="circle"> Time Clock Check In (SET UP IF STATEMENTS IF POSSIBLE) </li>)}
            </ol>
2
  • 1
    You have nested {!..}, you should only use merge syntax once...what are you trying to accomplish?
    – Adrian Larson
    Aug 30, 2016 at 18:12
  • I am trying to create an IF else statement that checks if the field Timeclockstartdate__c is filled, and if it is field then to output that value. If it is not filled then to not output anything. Aug 31, 2016 at 22:41

2 Answers 2

1

This should run your formula and render the results to the VF page. Try this.

rendered="{!IF(ISNULL(TimeclockStartDate__c), 
               NULL,
               '<li type=\"circle\"> Time Clock Check In (SET UP IF STATEMENTS IF POSSIBLE) </li>)' }"
6
  • Explain why your answer will fix the problem rather than just posting code please. Also try to put the code in a block so that it is readable rather than one long scrolling line.
    – Dave Humm
    Aug 31, 2016 at 8:54
  • Hi guys, I tried the code above and unfortunately I am getting "Error: Syntax error. Missing ')'" I tried to put a ")" in various places but it did not make a difference. Would it be helpful if i posted the whole code? Aug 31, 2016 at 22:45
  • I missed an end quote and I replaced the middle quotes with single quotes. Please copy and try again.
    – Apex N-u-b
    Sep 1, 2016 at 7:04
  • Still getting an error. It's this now: Error: EL Expression Unbalanced: ... {!IF(ISNULL(TimeclockStartDate__c), NULL, '<li type="circle"> Time Clock Check In (SET UP IF STATEMENTS IF POSSIBLE) </li>)' }" Sep 1, 2016 at 16:10
  • @ApexN-u-b any thoughts on this? Sep 2, 2016 at 18:57
0

In your example it looks like you are wanting to output the `` only if a value is present, to do this you could use a visualforce component such as an <apex:outputPanel> or <apex:outputText> which would give you the ability to conditionally render the segment within that element. I have put together the example you gave with an outputText component to do this conditional rendering.

<p> Completed Trainings: </p>
<ol style= "indent" margin= "10px 0px">
    <li type="circle"> <u>Core Training</u> </li>
    <li type="circle"> Staff Training </li>
    <apex:outputText rendered="{!NOT(ISNULL(relatedTo.TimeclockStartDate__c))}">
        <li type="circle"> Time Clock Check In: {!relatedTo.TimeclockStartDate__c}</li>
    </apex:outputText>
</ol>

The <apex:outputText> in the example above would provide the functionality to conditionally show the <li> element including the label, one consideration in the above example would be to look at formatting the value of {!relatedTo.TimeclockStartDate__c} into a user friendly manner.

something like this would give you a month/day/year date output.

<apex:outputText value="{0,date,MM/dd/yyyy}"> 
    <apex:param value="{!relatedTo.TimeclockStartDate__c}" /> 
</apex:outputText>

You must log in to answer this question.

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