Skip to main content
Known Participant
Nov 4, 2021 3:30 PM UTC
Question

using choose function with wherecontains in a record to display color based on condition.

Hi community,

I want to use choose instead of nested if to display status text in different colors.

I tried this expression and it throws this error A grid column [label=“Status”] has encountered an error. Expression evaluation error at function 'choose' [line 58]: Invalid index (1) for list: valid range is empty.

choose(wherecontains({fv!row[aRecord.status]}, cons!STATUSES)[1],"SECONDARY", "SECONDARY", "SECONDARY", "POSITIVE", "NEGATIVE", "STANDARD")

what am i doing wrong here?

Kind Regards,

Erik

6 replies

selvakumark
Participating Frequently
Nov 4, 2021 3:37 PM UTC

Hi Erik,

Have you checked the result of wherecontains() first to check whether it is returning the correct value?

mikes0011
Brainy
Nov 4, 2021 3:53 PM UTC

Yes, the code "wherecontains({fv!row[aRecord.status]}, cons!STATUSES)" should be first run by itself to make sure it returns a valid value.

The Expression Guru
csteward
Brainy
Nov 4, 2021 4:08 PM UTC

Agree with the other posts here.  This is essentially how I would typically implement, it also allows you to set a default with index() in the off chance you get a status you don't expect, an error will not be generated:

a!localVariables(
  local!index: index(wherecontains({fv!row[aRecord.status]},cons!STATUSES),1,1),
  
  choose(local!index,"SECONDARY", "SECONDARY", "SECONDARY", "POSITIVE", "NEGATIVE", "STANDARD")
)

erikb0001Author
Known Participant
Nov 4, 2021 4:12 PM UTC

Thanks you all for the replies, I will try and report back later.

stefanhelzle0001
Brainy
Nov 5, 2021 8:53 AM UTC

Wouldn't it be easier to use displayvalue() here. Something like this should do it

displayvalue(
  fv!row[aRecord.status],
  cons!STATUSES,
  {"SECONDARY", "SECONDARY", "SECONDARY", "POSITIVE", "NEGATIVE", "STANDARD"},
  "STANDARD"
)