Get a list of all users

cancel
Showing results for 
Search instead for 
Did you mean: 
PVanhoof
Member II

Get a list of all users

Jump to solution

Hi,

I have following code to list all users:

users = people.getPeople(null, 0)
for (var i=0; i<users.length; i++)
{
	log = users[i].properties.userName + "\n";
	logFile.content += log; 
}

However this does not work, I get an error on the log line.

I also tried users[i].properties["userName"], but that does not work either...

Error.png

2 Solutions

Accepted Solutions
abhinavmishra14
Advanced

Re: Get a list of all users

Jump to solution

That's not a correct way. people api retruns scriptbale object so basically you get string valued nodeRefs. 

You need to have actual node object in order to access properties. 

Update the line to :

log = search.findNode(users[i]).properties.userName + "\n";

These are REST APIs you can use as well to get the same details:

V1 API: http://<host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/people

Repo Api: http://<host>:<port>/alfresco/service/api/people

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

abhinavmishra14
Advanced
3 Replies
abhinavmishra14
Advanced

Re: Get a list of all users

Jump to solution

That's not a correct way. people api retruns scriptbale object so basically you get string valued nodeRefs. 

You need to have actual node object in order to access properties. 

Update the line to :

log = search.findNode(users[i]).properties.userName + "\n";

These are REST APIs you can use as well to get the same details:

V1 API: http://<host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/people

Repo Api: http://<host>:<port>/alfresco/service/api/people

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
PVanhoof
Member II

Re: Get a list of all users

Jump to solution

Thanks!

How do I check if the user account is enabled? I tried

if (isAccountEnabled(search.findNode(users[i]).properties.userName))

but that does not work.

abhinavmishra14
Advanced

Re: Get a list of all users

Jump to solution

people.isAccountEnabled() should work: 

https://docs.huihoo.com/javadoc/alfresco/4.2/repository/org/alfresco/repo/jscript/People.html#isAcco...)

~Abhinav
(ACSCE, AWS SAA, Azure Admin)