Forum Discussion

Aashishjain27's avatar
Aashishjain27
New Member
9 months ago
Solved

RLS with IF condition

Requirement is if following condition meets then only RLS should apply else RLS wont apply and user sees entire data.

following code not working id condition is meeting still user seeing entire data and RLS not applying. this all logic from single table which is filtering the data to fact and connected. workaround ? extratable ? Column ? 

 

= IF(
(
(CONTAINSSTRING([terr_id], "SCC") || CONTAINSSTRING([terr_id], "SNN"))
&& [terr_type] = "Territory"
),
LOWER(TRIM([emp_email])) = LOWER(TRIM(USERPRINCIPALNAME())),
TRUE()
)

  • lbendlin's avatar
    lbendlin
    9 months ago

    That's not how dynamic RLS works. You are supposed to hold a permission mapping table that is keyed off the USERPRINCIPALNAME and then controls the rest of the data model.

     

    You don't seem to have the required dimension tables for this?

5 Replies

  • Your condition translates into 

     

    =
    IF (
        ( CONTAINSSTRING ( [terr_id], "SCC" ) || CONTAINSSTRING ( [terr_id], "SNN" ) )
            && [terr_type] = "Territory"
            && LOWER ( TRIM ( [emp_email] ) ) <> LOWER ( TRIM ( USERPRINCIPALNAME () ) ),
        FALSE (),
        TRUE ()
    )

     

    This may not be what you intended.  You are also mixing static and dynamic RLS, which makes it even more complex.

    • Aashishjain27's avatar
      Aashishjain27
      New Member

      Its dynamic only. following logic is working but the issue issue when the condition doesnt meet like [terr_id] <>"SCC", I want user to see entire data but with this logic user not seeing any data

      IF (
          ( CONTAINSSTRING ( [terr_id], "SCC" ) || CONTAINSSTRING ( [terr_id], "SNN" ) )
              && [terr_type] = "Territory"
              && LOWER ( TRIM ( [emp_email] ) ) = LOWER ( TRIM ( USERPRINCIPALNAME () ) ),
          True (),
          FALSE()
      )
      • lbendlin's avatar
        lbendlin
        Super User

        That's not how dynamic RLS works. You are supposed to hold a permission mapping table that is keyed off the USERPRINCIPALNAME and then controls the rest of the data model.

         

        You don't seem to have the required dimension tables for this?