Hi all I have written a formula field Flagstatus which updates each time a choose a picklist value from the picklist field flag.The red flag is displayed when I choose red in the picklist and so on..
Formula field:
IMAGE(
CASE( Flags__c ,
"Green", "/img/samples/flag_green.gif",
"Yellow", "/img/samples/flag_yellow.gif",
"Red", "/img/samples/flag_red.gif",
"/s.gif"),
"status color")
My requirement is to somehow increase the size of the flag.When I searched I saw a method where I can provide the dimensions for the flag and I modified..
Modified formula:
IMAGE(
CASE( Flags__c ,
("Green", "/img/samples/flag_green.gif","green",30,30)
("Yellow", "/img/samples/flag_yellow.gif","red", 30, 30)
("Red", "/img/samples/flag_red.gif","yellow", 30, 30)
("/s.gif"),
"status color"))
BUt is not working.Syntax issue..
CASE(
Flags__c,
"Green",
IMAGE(
"/img/samples/flag_green.gif",
"green",
40,
40
),
"Yellow",
IMAGE(
"/img/samples/flag_yellow.gif",
"yellow",
40,
40
),
"Red",
IMAGE(
"img/samples/flag_red.gif",
"red",
40,
40
),
IMAGE("/s.gif", "status color")
)
Best Answer
Indenting and formatting your formulas is extremely helpful in finding syntax mistakes or cross-checking with the expected format. In this case, you'll note that CASE expects
CASE(expression,value1, result1, value2, result2,..., else_result)
and IMAGE expects
IMAGE(image_url, alternate_text, height, width)
Likewise, what you're trying to accomplish with the above formula could be put in the following terms to match with the parameters above
expression
), depending on its data (value
) - return a format (result
) to be used withinIMAGE
If I format your existing formula and add a comment to match with the expected format above, you can see your parenthesis are bunching the value used in
CASE
together with the format you'd want to return forIMAGE
.You'll need to separate them out like so
Note: you had mismatched labeling your image colors (red/yellow) as well
Testing quickly the above, you'll still get errors. If you look closer at it, you'll see that the value being returned to IMAGE() from CASE is
("url", "alternatetext",30,30)
. However, that's treated as all one input/parameter (string) inIMAGE
instead of 4 separate parameters.You'd have to duplicate your CASE for each parameter to achieve it the way you were doing
As you can see, it's not very efficient. Instead, you can flip your CASE and IMAGE so you can return the IMAGE() with all its properties set