Select to view content in your preferred language

Get PortalUser objects that belong to a group

10-03-2019 07:13 AM
Occasional Contributor

I am writing a tool that allows one user to share content created offline with other users.  Here's how it currently works:

  • User consumes feature service shared with them through a portal group and creates an offline geodatabase
  • User created new content within that offline geodatabase
  • User wants to share that content with other users who also have access to that same feature service

Pseudo Code is as follows:

  • I get a list of all groups in the Portal with which that feature service has been shared
  • I then cursor through all the collections of Admins, Members, and Users for each of those groups creating a master list of users that are eligible for sharing
  • All of those properties kick back the portal user id as a string

What I want to do is get the first and last name of each portal user to display in a list.  To do that I need to get a PortalUser object and I haven't found the combination of calls to make that happen.  I headed down this direction:

PortalQueryParameters gParams = PortalQueryParameters.CreateForItemsWithId(portalItem.ItemId);
PortalQueryResultSet<PortalUser> pUsers = await ApplicationManager.SessionManager.Portal.FindUsersAsync(gParams);

The portal item is the feature service and I figured this would give me all the PortalUser objects that had access to it, but it comes back with nothing.  I tried a couple of different but similar calls and none return any PortalUsers.

Anyone have any ideas on this?  Thanks in advance for your help ...

0 Kudos
2 Replies
MVP Regular Contributor

I think, and don't have an example...

But you would use: ArcGISPortal.FindUsersAsync Method (PortalQueryParameters).

The trick is you need to set the Query on the PortalQueryParameters correctly PortalQueryParameters.Query Property.

This is based on the portal API query strings User Search—ArcGIS REST API: Users, groups, and content | ArcGIS for Developers .

Not sure why the method to get groups from the item does not just give you an easy to work with enumeration of Groups instead of the convoluted way it seems to work

0 Kudos
Occasional Contributor

Ok I was eventually able to figure this out through a lot of trial and error as the docs don't really lay this whole thing out too well.  I had the user id and wanted to get the first and last name for that user.  Your query string for the PortalQueryParameters just needs to be the user id.  There really isn't a query you need to form here if it's that simple.  You then get a user back and you can hit the FullName property from there.

Thanks for pointing me in the right direction Joe.  Appreciate it ...

PortalQueryParameters userParams = new PortalQueryParameters(<User ID>);
PortalQueryResultSet<PortalUser> users = await Portal.FindUsersAsync(userParams);
string fullname = users.Results.ElementAt(0).FullName;

0 Kudos