Conditional Rendering on row action button based on combination of model field value and running user attribute?

  • 1
  • Question
  • Updated 3 years ago
I need to conditionally render a table row action button based on a combination of the running user attribute and a field value in the model.

For example, I have a user with a Role of "A". I also have a model field value which I can make the same as the Role, "A".

Can I conditionally render a row action button if the running user's attribute equals A and the row in the table has a model field equal to A? 
Photo of Ben Knecht

Ben Knecht

  • 946 Points 500 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ben,

Are you asking for one condition: fieldValue = userRole,

Or are you asking for two conditions:

fieldValue = X
userRole = Y

?


If the first, just set your condition so that the field value equals the user role with merge syntax {{$User.userRoleId}} (if you need the actual user Role Name, you'd just need to create a model for the current user, and reference it like so: {{$Model.CurrentUser.data.0.Role.Name}})

If the latter, just add both as rendering conditions and require ALL conditions to be met.
Photo of Ben Knecht

Ben Knecht

  • 946 Points 500 badge 2x thumb
Hey Matt,

Thanks for the response. The second option is what I'm looking for - two conditions - fieldValue = x and userRole = Y. 

"If the latter, just add both as rendering conditions and require ALL conditions to be met." - that makes sense. However, I just realized a snag in my plan. The userRoile will not be the same value as the model field. It looks like I can't create a custom field on the user record and use that for rendering conditions. 

Any ideas? I'm completely stuck here. Thanks for any help or feedback.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ben,

Why can't you create a custom field on the user object?

If you can provide a more complete description of your use case, we can probably help you find a way.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Why can you not create a custom object on the user record?  is there some "edition limitation" here? 
The custom field will not show up in the list of user attributes always available for conditions,  but you can always get around that if you create a "current user model"  and include the custom field in your model.  Then you can do conditional rendering on that model / field combination in addition to your actual fieldValue. 
(Edited)