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
Brad BothBrad Both 

IF Statement not returning what I need

Hey, I'm fairly new to this and haven't been able to find an answer elsewhere, or I have missed it. What I'm trying to accomplish is checking to see if the string has at least 2 characters and if it does I use that string inside a URL to create a barcode. If it is less than 2 then it will return a blank image instead of the barcode.

It just doesn't seem to be working that way, when I try to use the variable within the URL it "cuts" the URL at that point where I put it in and returns the basic barcode from the site.

-----

<apex:pageBlock >
    <apex:pageBlockSection id="Items" columns="1" 
            showHeader="true" collapsible="false">  
      <apex:pageBlockTable value="{!myOrder.OrderItems}" headerClass="hidden"  cellPadding="4"  border="0" var="item" > 
                            
      <apex:column headerValue="Customer P/N" width="25%"><apex:image id="CusPN" value="{!IF(LEN(item.PriceBookEntry.Product2.ProductCode)>2, 'http://generator.barcodetools.com/barcode.png?gen=0&data={!item.PriceBookEntry.Product2.ProductCode}&bcolor=FFFFFF&fcolor=000000&tcolor=000000&fh=8&bred=&w2n=2.5&xdim=2&w=250&h=30&debug=1&btype=2&angle=0&quiet=0&balign=2&talign=2&guarg=1&text=1&tdown=1&stst=1&schk=0&cchk=1&ntxt=1&c128=0', '---')}"/>
                </apex:column>
                
                <apex:column headerValue="CCM P/N" width="25%"><apex:image id="CCMPN" value="http://generator.barcodetools.com/barcode.png?gen=0&data={!item.PriceBookEntry.Product2.ProductCode}&bcolor=FFFFFF&fcolor=000000&tcolor=000000&fh=8&bred=&w2n=2.5&xdim=2&w=250&h=30&debug=1&btype=2&angle=0&quiet=1&balign=2&talign=2&guarg=1&text=1&tdown=1&stst=1&schk=0&cchk=1&ntxt=1&c128=0}"/>
                </apex:column>

-----

So those are the two columns, only the one needs to be checked while the other one works fine. Again my knowledge is fairly limited within VisualForce and Apex, and as far as I can tell when I'm trying to use the variable within the IF statement using { } it is cause the URL to get shortened to "http://generator.barcodetools.com/barcode.png?gen=0&data=" which is exactly what I'm getting as an output.

Thanks for all the help!

Best Answer chosen by Brad Both
Hargobind_SinghHargobind_Singh
Hi, in your IF construct, try not to use curly braces {!} within curly braces, VF won't read them. Just use the variable name and use concatenation (if that is a function) or "+" to combine strings
item.PriceBookEntry.Product2.ProductCode + '&bcolor=FFFFFF&fcolor=000000&tcolor=000000&fh=8&bred=&w2n=2.5&xdim=2&w=250&h=30&debug=1&btype=2&angle=0&quiet=0&balign=2&talign=2&guarg=1&text=1&tdown=1&stst=1&schk=0&cchk=1&ntxt=1&c128=0', '---')}