cancel
Showing results for 
Search instead for 
Did you mean: 

Search for Document by name and retrieve nodeID

anand_patel18
Champ in-the-making
Champ in-the-making
Hi,

I'm new to alfresco and programming, I'm running a webscript where I need to search for a xml file and retrieve its contents to use. The file name will depend on the username but the file retrieved will always be from the same path.

I've got it running but it only works when I specify the actual nodeID:


// Search and locates file
var node = search.findNode("workspace://SpacesStore/3177cfa2-532c-4970-afbc-df929d07bc3c");

// Take the content of that node
var content = node.content;

// Puts the content as XML
var xml = new XML(content);

// Extracts the variable you want
var employeename = xml.employeename;
Grade = xml.Grade;
currentPM = xml.CurrentPM;
currentMD = xml.CurrentMD;
Month = xml.Month;
Day = xml.Day;
Year = xml.Year;
PEselfPA = xml.PEselfPA;
PEselfFA =xml.PEselfFA;
PEselfC =xml.PEselfC;
PEselfCT = xml.PEselfCT;


// setup model for response template to use variable
model.employeename = employeename.toString();
model.Grade = Grade.toString();
model.currentPM = currentPM.toString();
model.currentMD = currentMD.toString();
model.Month = Month.toString();
model.Day = Day.toString();
model.Year = Year.toString();
model.PEselfPA = PEselfPA.toString();
model.PEselfFA = PEselfFA.toString();
model.PEselfC = PEselfC.toString();
model.PEselfCT = PEselfCT.toString();

Since this works I've been looking for ways to search for a specific document based on its name (e.g. admin.xml) from the path (e.g.Company Home/Data Dictionary/Models) and once located I want to get its nodeid as a string, once i've done this I can place that string in my above code (e.g. var node = search.findNode("STRING"):smileywink: and it should work.

I've been searching all over Alfresco's wiki and I thought I could use one of the luceneSearch or findNode API's but I dont understand how to user them (i'm not a programmer). I'm actually doing this part of an University project so I cant really find help from anywhere else. 

Could someone please provide me with an example or some help so I can understand the search API's better.

Thanks
2 REPLIES 2

toze
Champ in-the-making
Champ in-the-making
you can throw the root nodeRef and the name of the documet, and search for child of that node
Or you can use Lucene query's
Or you can use Cmis

anand_patel18
Champ in-the-making
Champ in-the-making
Thanks, Is there any chance to get an example? I'm not a programmer so I don't understand the how to actually use the Lucene search etc.