Help with slice enumlist expression

Hello friends, i have an app that uses an user system to decide who sees what and all that stuff, but i’m having problems using an enumlist to assign tasks.

I have a CurrentUser slice with a filter condition that is [Email]=useremail(), the User table has a role (enum) and a tasks (enumlist base type ref to the tasks table) columns.

I’m trying to filter the Tasks table using both the role and the tasks columns, this is the expression that i’m using for the CurrentUserTasks slice:

SWITCH(
			INDEX(CurrentUser[Role],1),
			"Residente de obra",IN([Task_Id],INDEX(CurrentUser[Tasks],1)),
			"Director de obra",IN([Task_Id],INDEX(CurrentUser[Tasks],1)),
			TRUE)

It works when there’s only a single task assigned, but if i assign more than one it just doesn’t show them, any ideas?

Hi @Rafael_ANEIC-PY

There is something with EnumList and List that is annoying sometime, I remember having struggled with it a few weeks ago.
A suggestion, but I’m not sure that will solve your issue : do you have the same behavior if you turn your column [Tasks] into a VC of type List, instead of EnumList ? Or, create a VC for this purpose and use this one in your switch expression ?

(There is 1 point that catches my attention: the switch output seems to be the same for your two expected values, is it OK for you ?)

2 Likes

also in this expression I believe the part INDEX(CurrentUser[Tasks],1)) will always return 1 value from a list?
So I believe the part IN([Task_Id],INDEX(CurrentUser[Tasks],1)) will return 1 value of [Task _D]

Maybe you wish to try IN([Task_Id],CurrentUser[Tasks],1) in place of IN([Task_Id],INDEX(CurrentUser[Tasks],1)) in the expression?

Something like
SWITCH(
INDEX(CurrentUser[Role],1),
“Residente de obra”,IN([Task_Id],ICurrentUser[Tasks]),
“Director de obra”,IN([Task_Id],ICurrentUser[Tasks] ),
TRUE)

2 Likes

I think I’ve had a similar problem trying to do something along those lines. My issue seemed to be rooted in my having edited the “item separator” of the enumlist field. It wouldn’t return to what I’d expected the behaviour to be, even after I restored the item separator option (I’d switched the default " , " to ", "). To get it to work, I “reconstituted” the list by casting it to a string, removing the spaces, and splitting the resultant string on the commas to form a new list, replacing [enumlist] with something like:

SPLIT( SUBSTITUTE( CONCATENATE(enumlist), " ", "", ), "," )

4 Likes

How I’d do it:

ISNOTBLANK(
  FILTER(
    "CurrentUser",
    SWITCH(
      [Role],
      "Residente de obra",
        IN([Task_Id], [Tasks]),
      "Director de obra",
        IN([Task_Id], [Tasks]),
      TRUE
    )
  )
)

Or (@aforrester is on the right track):

SWITCH(
  ANY(CurrentUser[Role]),
  "Residente de obra",
    IN([Task_Id], SPLIT(("" & CurrentUser[Tasks]), " , "))
  "Director de obra",
    IN([Task_Id], SPLIT(("" & CurrentUser[Tasks]), " , "))
  TRUE
)

Or:

OR(
  NOT(
    IN(
      ANY(CurrentUser[Role]),
      LIST("Residente de obra", "Director de obra")
    )
  ),
  IN([Task_Id], SPLIT(("" & CurrentUser[Tasks]), " , "))
)
4 Likes

Oh Yes @Steve , SPLIT() is required to normalize the list of lists created with CurrentUser[Tasks] :slight_smile: :+1:

3 Likes

Woah ! thanks a lot guys, y’all made short work of my problem haha, i used this expression and it worked like a charm.

4 Likes

My god the readability of your expressions. I am so ashamed of my indentation…

For whatever it’s worth, in my case INTERSECT did not work as it previously had after I’d customised the item separator to ", " (comma space). It still did not work as expected even after I un-customised it back to the default. Pretty non-specific and un-troubleshootable information, I know, but thought I’d mention it in just case it triggers a useful idea in any future issue

3 Likes

SPLIT() is very picky about what it’s given as its first argument. It really, really wants a Text or LongText value. If given something else, SPLIT() has its own method for converting what it’s given to text. In the case of lists, it replaces the default " , " (space-comma-space) separator with just "," (comma). I prefer to force the conversion myself using the method above.

3 Likes