In the User Management connector for Public APIs, the ApplicationRoles_Query server action under Users → Roles returns a list of application roles based on filters. However, when I bind this list to a dropdown, it displays duplicate roles. How can I ensure only unique roles appear?
Hi Amrata,
I think you are fetching roles from ApplicationRoles_Query server action from one or more environments like DEV and QA if you haven't provided stage key that's why its showing roles repeated in the dropdown from both environment in ODC.
In my opinion if your roles are created in any one module then fetch roles from that application only.
To do that you have to get all application from current environment (DEV or QA) and then pass the application key to ApplicationRoles_Query to get all roles from that module.
Hope this helps .
To remove duplicate roles from the ApplicationRoles_Query server action results in the OutSystems User Management Connector's Public APIs, you can process the results systematically. Here's how you can achieve this:
ApplicationRoles_Query
Load the Results: Fetch the results from ApplicationRoles_Query. This will include all roles associated with different users.
Eliminate Duplicates: Use a List Distinct logic to filter out duplicate rows. You can do this using the List manipulation tools available in OutSystems. Typically, you will need to:
List
RoleName
RoleID
Implement Aggregates or Server Actions: If you're using aggregates directly in your application, add a filter condition or make use of the "Group By" functionality which can help collapse duplicate rows into unique ones automatically (specific to an attribute, such as RoleName).
Example of a grouping scenario in an aggregate:
Alternative Using SQL (if applicable): If your data is retrieved using Advanced Queries (SQL), you can eliminate duplicates with a SELECT DISTINCT statement. For instance:
SELECT DISTINCT
SELECT DISTINCT RoleName FROM {UserRole} WHERE UserId = @UserId
Replace UserRole with your actual table name and UserId with the filter parameter.
UserRole
UserId
These approaches ensure you're working with unique role data, whether you're using aggregates, server actions, or SQL queries. For a detailed example, the forum discussion on How to list all users with certain roles might offer additional insights into consolidating role data dynamically.
Let me know if you encounter any specific challenges while implementing this!
Hi @Amrata Kuchekar ,
Have you tried ListDistinct option?
https://success.outsystems.com/documentation/11/reference/outsystems_apis/system_actions/#Client_ListDistinct
Regards,
Manish Jawla
Hii @Amrata Kuchekar
You can create a local variable and use a For Each loop with ListFilter/ListAny to check for existence before appending to the new list.
Aditya Dubey
In your case, you have used an API. We can also try to make the list distinct, but sometimes this causes issues—for example, when there are extra spaces in the records, duplicate values may still appear. To avoid this, I used an aggregate instead of the API and implemented custom logic to remove duplicate records. This same logic can also be implemented inside a server action. You do not need to change much—only bind the values returned from the API to a structure and apply the duplicate-removal logic there. I have shared the OML; please try this approach, as it should help you
https://personal-udaksfpd.outsystemscloud.com/RemoveDublicateList/DublicateRecords?_ts=639029699276031527
Hi,
I think most of our guys proposed the built-in ListDistinct client / server action to resolve the outcome.
In my opinion, you should find out the root cause. I believe you are using the ODC, it centralizes the user once and allows us to grant permission for role on applications and environments. Is it possibly caused by this? Any built-in filters by environment or application? To investigate more, please add more data to show on the dropdown, not just name. Moreover, you can log the returned data from that public API to understand more about the issue
My guess is that you are not using the filter on stage (environmentKey)