Urgent Help Needed: Variable for CURRENT USER ROLE

Good day to all.

Please note I am trying to hide a section in a program stage based on the logged on users role/group. I am looking for a variable for this purpose, such as V{current_date} to set the program rule but I could not find.

Can anyone kindly assist me? Your help is very much appreciated.

1 Like

hello @MSP
The function you’re looking for is d2:hasUserRole()
It might not work on versions before 2.29

1 Like

Thank your @brian , for your assistance. Let me check and confirm soon.

1 Like

Hi @brian,

Please note I have used the below rule to hide a section but it does not hide the section:

!(d2:hasUserRole(‘EWAdOcRwzFN’))

I have actually copy pasted the “uid” from the DB to avoid spelling mistakes. I cleared the cache a couple of times, used a different browser but in vain. Do you see anything wrong in my rule?

*Just to make it clear, I want to hide the section for all other roles.

BTW, We are using DHIS2 Version 2.29, Build 0b4de69.

1 Like

Sorry. In double checking, the function is not found in documentation before 2.31. And, it works in Play 2.31 but not Play 2.29 (below, see last warning)


.
However, you can also share data elements with a specific user GROUP through sharing settings.

1 Like

Thank you very much @brian for sparing your invaluable time to assist me. No issues.

Let me try Data element sharing and update.

1 Like

Hi @brian,

I tried sharing the Data Element but it did not work. Then I searched the document you shared and found the following:

And I realised that the Data Elements have only Meta Data Sharing as shown below:

image

Whereas, the Program and Program Stage has both Meta data and Data sharing:

image

Therefore, I guess user access restriction at Data Element level is not possible in DHIS2.

Is it possible for you reconfirm? I am also requesting @dhis2-platform to confirm this.

Many thanks for your time and guidance.

1 Like

@Shurajit_Dutta , @Markus
I am not sure you can deny access to programstage sections, and hiding metadata does not help much. Any work around, you can suggest for @MSP

Thanks,
Emma

1 Like

I realize this is very old, but wondering if anyone has gotten a program rule to work for hiding a section based on user role. (v 2.36)

I never had this use case, but you can use this program rule to achieve what you want

d2:hasUserRole( <user_role> )

With this you can check if a user as this role and hide a section.

Hope this will help you.

1 Like