cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript - How to find the user name based on full name?

nimbus1958
Confirmed Champ
Confirmed Champ

Hello,

It may seems trivial but I cannot find the info!

Using the javascript API, I am lost!

Finding the full name based on user name in no problem but somehow, I cannot find a user name from the full name!

Thanking you in advance,

Pablo

!I am using Alfresco 5.2!

9 REPLIES 9

angelborroy
Community Manager Community Manager
Community Manager

There is not function available out-of-the-box to get the username from the Full Name. In fact, Alfresco is not storing the Full Name, so you need to split the string into firstName and secondName. For example, for "Alice Beecher", first name is "Alice" and second name is "Beecher".

From this point, you need to use the search API. Something similar to following snippet.

var results = 
search.query({query: "cm:firstName:'Alice' AND cm:lastName:'Beecher'"});
Hyland Developer Evangelist

I have tried the following but with no results:

var results =
  search.query({query: "cm:firstName:'Pablo' AND cm:lastName:'Severin'"});

It gives me an error:

0318127301 Failed to execute search: cm:firstName:'Pablo' AND cm:lastName:'Severin'

I have tried: 

var results = search.query({query:"cm:firstName='Pablo' AND cm:lastName = 'Severin'"});
logger.log(results);

It returns empty but there is no error now!

I have also tried without the single quotes but it is also empty without errors!

Strange!

luca_biondo
Confirmed Champ
Confirmed Champ

Hi, if i'm not mistaken the query grammar is missing somenthig. If we agree we are writing the query in lucene language (if not, my mistake sorry) the right query will be:

@cm\:firstName:"Pablo" AND @cm\:lastName:"Severin"

And once you write it in your String you should escape properly, something like:

@cm\\:firstName:\"Pablo\" AND @cm\\:lastName:\"Severin\"

Hoping I was usefull

Kind regards

Luca

Thanks Luca, I have a node now!

Got to just find a way to get the userName from it.

Pablo

luca_biondo
Confirmed Champ
Confirmed Champ

You'r welcome Smiley Happy,

So, again, if I'm not mistaken, from first name and last name you would like to find the user name. Now you have a NodeRef object, if I were you i would try to use the NodeService to get my property. Something like:

nodeService.getProperty(nodeRef, ContentModel.PROP_USER_USERNAME)

I only tried it, quickly, on the node browser so let me know if it works!

Luca

No luck!

var results = search.query({query:"@cm\\:firstName:\"Pablo\" AND @cm\\:lastName:\"Severin\""});

returns:

DEBUG - Node Type: {http://www.alfresco.org/model/content/1.0}person, Node Aspects: [{http://www.alfresco.org/model/application/1.0}configurable, {http://www.alfresco.org/model/system/1.0}cascadeUpdate, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/imap/1.0}imapPreferences, {http://www.alfresco.org/model/system/1.0}localized, {http://www.alfresco.org/model/content/1.0}preferences, {http://www.alfresco.org/model/remotecredentials/1.0}remoteCredentialsSystemContainer]

The nodeService gives me an error!

I do not know what to do now!

Pablo

use are using javascript. refer to the scriptNode API for getting the property:

results[0].properties.userName;

Regards,
Abbas

Super!

It works! Thank you all for you help!

Pablo