Help Finding a Tutorial - Format Rules Based on User Roles?

I saw a guide on this very topic not too terribly long ago but now I cannot find it. What I am looking to do today is create a couple of formatting rules that color the values of a certain column based on the "role" of the user that set the value.

I have a table that contains two columns, a user email address and a role. There's currently only two people in there, myself and a test subject, but that part is likely irrelevant.

Let me try to set this up. The table i want to affect is called Patients and there is a column called Seen that is a simple yes/no field that marks that the patient has been seen. I have a bot that resets this field at midnight each night.

The app currently has a button on a patient record that the doctor or nurse can press to log that they have visited a patient in hospital on their rounds for that day. This captures the timestamp of the visit, as well as the provider who did the visit, and logs the visit in a secondary table with a ref back to the patient record.

I currently have a working format rule that changes the color of the patient name and gives it an icon to indicate that the patient has been seen today, and at the moment this is based on detecting that the value of Seen is yes.

I would like to further refine this to change the color based on the role of the user who created the Seen record, so if the user role is Provider, its one color, if the user is Non-Physician Provider, its another color, and so on.

I suppose i need help understanding how to craft my expression to do the following:

change the color of these fields to this color if  the value of [Seen] is equal to "yes" AND the value of USEREMAIL(), as seen in the "User Roles" table has the value of "Provider" in the Role column.

Side question, how long did it take you guys to feel like you have truly come to terms with expressions in AppSheet? In some respects, i am amazed at what i have been able to accomplish (with help from this community) so far, having never done anything even remotely related to app development, but on the other hand, i am equally amazed at how easy it is to get stuck on little things....

Thanks

Solved Solved
0 3 90
1 ACCEPTED SOLUTION


@mykrobinson wrote:

i am equally amazed at how easy it is to get stuck on little things....


Every language has its quirks  that a developer, even experienced developers, can get hung up on trying to figure out.  I think It's because the "little things" are not well posted. 

Learning expressions is easier if you have had development or sheet formula experience.  After about 4 years, there are still some things I am learning, or at least understanding better, concerning expressions.

As to your Format Rule expression:

AND([Seen] = "Yes",
    ANY(SELECT(User Roles[Role], [User Email] = USEREMAIL())) = "Provider"
)

This assumes that [Role] and [User Email] are columns in the User Roles table.  If not, you will need to adjust the column names. 

 

View solution in original post

3 REPLIES 3


@mykrobinson wrote:

i am equally amazed at how easy it is to get stuck on little things....


Every language has its quirks  that a developer, even experienced developers, can get hung up on trying to figure out.  I think It's because the "little things" are not well posted. 

Learning expressions is easier if you have had development or sheet formula experience.  After about 4 years, there are still some things I am learning, or at least understanding better, concerning expressions.

As to your Format Rule expression:

AND([Seen] = "Yes",
    ANY(SELECT(User Roles[Role], [User Email] = USEREMAIL())) = "Provider"
)

This assumes that [Role] and [User Email] are columns in the User Roles table.  If not, you will need to adjust the column names. 

 

thank you. before actually implementing this, i will do as i have been doing and first look up the documentation on the functions that make up this expression, as i do truly want to understand what i am doing so that my line of question will eventually subside, and i'll start answering more than i have asked ๐Ÿ™‚

thanks again. I think i understand the expression but i need to think this through a bit further, as it seems this relies on the currently signed in user. What i need is for it to check the most recent "Seen by Provider" entry and query whether the person who logged that record is a provider. Lemme try to work through this one for a bit, as I have another expression elsewhere that returns a value based on the most recent entry in a table, I can use that as a point of reference for tweaking this expression.

Top Labels in this Space