0

enter image description here

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..

enter image description here

enter image description here

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") )

1 Answer 1

5

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

  • For a given field (expression), depending on its data (value) - return a format (result) to be used within IMAGE

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 for IMAGE.

IMAGE(
    CASE( 
        Flags__c,                                                /* expression */
        
        ("Green", "/img/samples/flag_green.gif","green",30,30)   /* value1 */
        /* Missing comma from above expression */
        
        /* Wrong alternate text for color */
        ("Yellow", "/img/samples/flag_yellow.gif","red", 30, 30) /* result1 */

...

You'll need to separate them out like so

IMAGE(
    CASE( 
        Flags__c ,                                         /* expression */
       
        "Green",                                           /* value 1 */
        ("/img/samples/flag_green.gif","green",30,30),     /* result 1 */

        "Yellow",                                          /* value 2 */
        ("/img/samples/flag_yellow.gif","yellow", 30, 30), /* result 2 */

        "Red",                                             /* value 3 */
        ("/img/samples/flag_red.gif","red", 30, 30),       /* result 3 */

        ("/s.gif", "status color")                         /* else result */
    )
)

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) in IMAGE instead of 4 separate parameters.

You'd have to duplicate your CASE for each parameter to achieve it the way you were doing

IMAGE(
    CASE(
        Flags__c,

        "Green",
        "img/samples/flag_green.gif

        ..rest of case for just url
    ),

    CASE(
        Flags__c

        "Green",
        "green",

        ..rest of case for just alternate text

...and so on

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

CASE(
    Flags__c,                               /* expression */

    "Green",                                /* value 1 */
        IMAGE(                              /* result 1 */
            "/img/samples/flag_green.gif",
            "green",
            30,
            30
        ),

    "Red",
        IMAGE(
            "img/samples/flag_red.gif",
            "red",
            30,
            30
        ),

    ...rest of your colors/images

)
13
  • Gonclaves Is this the way...........IMAGE( CASE( Flags__c, "Green", "img/samples/flag_green.gif "green", 30, 30 ), CASE( Flags__c, "Red", "img/samples/flag_red.gif "red", 30, 30 ), CASE( Flags__c, "Red", "img/samples/flag_yellow.gif "yellow", 30, 30 ), )
    – user110290
    Mar 2, 2022 at 15:52
  • Look at my last example - you'll want to nest the IMAGE() within CASE(). You should be able to follow the syntax to complete the rest Mar 2, 2022 at 16:01
  • @Gonclaves Okay I believe I have updated your suggestions.I have added it and the end of my question as it is a bit long.Still a syntax error.
    – user110290
    Mar 2, 2022 at 16:15
  • I'm not sure you understood what I was saying. Look at the final example in my answer (I'll updated it with more of it, but you should be able to follow the structure). You just need one CASE at the top and then return one IMAGE for each different scenario. Mar 2, 2022 at 16:42
  • @Gonclaves I get it now.Thanks so much for the help.I did this way and I have uploaded the snip.I have closed all the conditions accordingly.Still it remains.Btw Thanks.....
    – user110290
    Mar 2, 2022 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.