04-17-2019 04:09 AM
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!
04-17-2019 09:49 AM
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'"});
04-18-2019 02:27 AM
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'
04-18-2019 03:36 AM
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!
04-18-2019 04:06 AM
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
04-18-2019 04:16 AM
Thanks Luca, I have a node now!
Got to just find a way to get the userName from it.
Pablo
04-18-2019 04:26 AM
You'r welcome ,
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
04-18-2019 04:36 AM
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
04-18-2019 04:43 AM
use are using javascript. refer to the scriptNode API for getting the property:
results[0].properties.userName;
04-18-2019 04:46 AM
Super!
It works! Thank you all for you help!
Pablo
Explore our Alfresco products with the links below. Use labels to filter content by product module.