Question
· Apr 26, 2022

COS script for getting users from Security.Users is returning an empty result

I wrote this COS script that I can run in a terminal session to get a view of the cache users:

set hdl = ##class(%Library.ResultSet).%New()
set hdl.ClassName = "Security.Users"
set hdl.QueryName = "Detail"
set sc = hdl.Execute()

while hdl.%Next() { do hdl.%Print() }

I know this is a bit rudimentary  but this seems to be the correct script to get users. But looking at one of the clients AIX based instances there are about 3900 users. But this script returns no results. In fact, after the execute if I issue "w hd.%Next()" it returns 0. I look at "Do DisplayError^%apiOBJ(sc)" and the message is:

ERROR #5660: Query 'Security.Users:Detail' does not exist

which doesn't seem possible. Not sure what I am missing with this script

Product version: Caché 2017.1
Discussion (4)1
Log in or sign up to continue

@Kevin McGinn, use the recommendations passed by @Robert Cemper 
and you need to pass "*" on Execute() method, sample works code below:

ClassMethod getSecurityUsers() As %Status
{   

  set rs=##class(%ResultSet).%New()
  set rs.ClassName="Security.Users"
  set rs.QueryName="Detail"
  //Alternatively, you can bind the result set object to a query
    //set rs=##class(%ResultSet).%New("Security.Users:Detail")
    
  set sc=rs.Execute("*")
 
  If $$$ISERR(sc) Do DisplayError^%apiOBJ(sc) Quit sc
 
  While rs.%Next()
 
 
  ;===== Fields can be used
  /*Name:%String,FullName:%String,Comment:%String,Enabled:%String,ExpirationDate:%String,
  Roles:%String,GrantedRoles:%String,Namespace:%String,Routine:%String,LastPasswordChangeTime:%String,
 LastLoginTime:%String,LastLoginService:%String,LastLoginDevice:%String,LastInvalidLoginTime:%String,LastLoginError:%String,InvalidLoginAttempts:%String,LastInvalidLoginService:%String,LastInvalidLoginDevice:%String,Type:%String,EmailAddress:%String,PhoneNumber:%String,PhoneProvider:%String,AccountNeverExpires:%String,PasswordNeverExpires:%String,AutheEnabled:%String,CreateDateTime:%String,CreateUsername:%String,LastModifiedDateTime:%String,LastModifiedUsername:%String,LastModifiedInfo:%String*/
 
  rs.Get("Name")_" - "_rs.Get("FullName")_" - "_rs.Get("Enabled")_" - "_rs.Get("LastInvalidLoginDevice")_" - Roles:"_rs.Get("Roles"),!
 
  }

Quit $$$OK
}

Output: 


 Version: Ensemble 2017.2.2

I believe the same works for you, I searched this link on documentation (Cache 2017):
Caché & Ensemble 2017.1 - Documentation - Security.Users