Query Portal for All Users

1071
4
Jump to solution
03-08-2018 03:24 PM
AndrewLindley
New Contributor III

I'm trying to run a query against portal to return all the registered users, but can't figure out how to get a wildcard variable to work.

This works:

let queryParameters = {
  query: "username:" + portal.user.username
};
portal.queryUsers(queryParameters)
.then(function(result){
  console.log(result);
})‍‍‍‍‍‍‍

But I need to do something like this, which doesn't work:

let queryParameters = {
  query: "username:*"
};
portal.queryUsers(queryParameters)
.then(function(result){
  console.log(result);
})

Any ideas are much appreciated.

Tags (3)
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Andrew,

  Do a query for your orgid like this:

orgid:HdNMW2j6UI55aLXm

and do not have username in the query

View solution in original post

4 Replies
AndrewLindley
New Contributor III

Update:

Ok, some cooky stuff going on here.

For the sake of meeting deadlines I tried implementing this workaround:

let queryParameters = {
  query: "username:a* OR username:b* OR username:c* OR username:d* OR username:e* OR username:f* OR username:g* OR username:h* OR username:i* OR username:j* OR username:k* OR username:l* OR username:m* OR username:n* OR username:o* OR username:p* OR username:q* OR username:r* OR username:s* OR username:t* OR username:u* OR username:v* OR username:w* OR username:x* OR username:y* OR username:z* OR NOT username:esri*",
  num: 1000
};

.. querying for every letter followed by the wildcard variable '*' returns all of the users who's username starts with a lowercase letter. Pretty tedious, but progress.

The problem is it doesn't return usernames that begin with an uppercase letter. OK, I thought, I'll just brute force it and add all uppercase letters followed by the wildcard variable to the query too.. but that doesn't work!

Changing all of the letters to uppercase in the above snippet still only returns lowercase usernames. The only way to return a username that begins with an uppercase letter is to query for the exact username, which obviously doesn't work for loading all users dynamically.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Andrew,

  Do a query for your orgid like this:

orgid:HdNMW2j6UI55aLXm

and do not have username in the query

AndrewLindley
New Contributor III

This did the trick, thanks!

0 Kudos
AndresCastillo
MVP Regular Contributor

Hi Andrew,

Can you share more of your JS script, like what you had to require for this to work?

0 Kudos