User Names in a tracked entity attribute?

Hi,
How can I get User Names to show in a tracked entity attribute? I’ve explored Sdk.d2().UserModule but not found it.

Hi @RahmanMonjur,

I am not sure if I get the question. The name of the current logged user can be got by d2.userModule().user().blockingGet().name(). But if you mean the attribute name of the trackedEntityAttributeValues, you have to get the name in the TrackedEntityAttribute repository by using the uid in the attribute value.

If that does not solve the question please give me more details about what you aim to show.

Hi @vgarciabnz,
Sorry for not being so clear. I mean to say to use ValueType USER_NAME in android. I would like to show some dhis2 user name in a dropdownlist of an attribute of which value type is USER_NAME.

Hi,
I am sorry but information about other users is not downloaded right know. The reason not to include it was that the number of users in the system could be very very high. But this is something we will probably include in the next version of the SDK.

Thanks for considering this to include in the SDK next. In the meantime, can I download the user names by api? If yes, I was wondering if you could show me a way to do that.

Well… in the SDK we don’t support performing custom queries to the API, but there is a way to do it. Notice that the SDK does not support it and the code could be broken in the next version.

The class d2 exposes a retrofit object, which is used to create the http queries. So you could:

Take into account that the execution of the service cannot be done in Android main thread.

If you find any issues we can have a short call if needed.

1 Like

Hi Victor, I’ve tried to create the model and service for Username like the way Constant was created. But I’m getting an error while creating the model class. It’s saying Cannot Resolve Symbol AutoValue_Username. I’m not sure why this is happening. I’m using https://github.com/RahmanMonjur/dhis2-android-skeleton-app/tree/ereg_matlab_test codes. I was wondering if you can help me to find the error.

Hi @RahmanMonjur,
Although I have not found a solution to make it work, I know that the problem has to to with the annotations to build the column adapters in the base class (BaseIdentifiableObject). The app is missing some libraries to make it work (like auto-value-cursor) but also the annotations are not well exported in the SDK library. We will let you know if we have news about it.
Anyway, you can use the existing User class to query the /users endpoint. Do you want to persist the user list in the database? We can have a call to see the details if needed

Thanks again @vgarciabnz.
I’ve added auto-value-cursor in the build.gradle file. Now, the visible error has gone but when I run this error: package $$AutoValue_Username does not exist when I compile it.
Yes, we can use the User class. I was taking an opportunity to create a new class in the AutoValue way. However, I’ve changed the Service accordingly by User class. Also called the service in MainActivity.Java under onCreate method. You may look onto it.
It would be helpful for me if you really spare some times for me a call to solve this issue. Appreciating it. Please let me know when you have time.