cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Association

tytanix
Champ in-the-making
Champ in-the-making
Hello everyone! I've implemented a custom model with an association called relatedDocuments. Now, i have to crate a javascript to retrieve the list of the relatedDocuments associated to a specific document. Does an API to do this exist?

I've tried with "document.properties["tr:relatedDocument"]" but it has returned NULL.

I need that because i'm trying to create a link between my document based on their metadata. I've set up a rule that, on update of content in a folder, will search in the repository if exists a document the could be linkable to the one updated.
The first execution works ok. Following executions result in error probably because there isn't an if statement to check if the association is a duplicate one.

I'm using the following scripts:

<blockcode>
function main()
{
   var cod_off = document.properties["tr:cod_off"];
         logger.log("######## VALUE OF COD OFF #########" + cod_off);
   
   var query = "@tr\\:cod_off:" + cod_off;
         logger.log("###### VAR QUERY CONTENT ######" + query);
         
   var results = search.luceneSearch(query);
   
   var resultTitle;
   var documentTitle = document.properties["cm:title"];
   
   var relatedDocs = document.properties["tr:relatedDocument"];
   var count = relatedDocs.length;
         logger.log("### VALUE OF COUNT RELATED DOCS ####" + count);
   
   for (var i = 0; i<results.length; i++)
   {
      
      resultTitle = results.properties["cm:title"];
      
      if(resultTitle !== documentTitle)
      {
         logger.log("#### FOUND DOCUMENT TITLE ######" + resultTitle);
         
         document.createAssociation(results, "tr:relatedDocument");
         results.createAssociation(document, "tr:relatedDocument");
      }
   }

}

main();
</blockcode>

If anyone knows how to retrieve the list of associated document to another, please answer me.

Best regards.
2 REPLIES 2

niketapatel
Star Contributor
Star Contributor
Hi Tytanix

You can retrieve association with below js api based on your requirement

assocs, sourceAssocs, childAssocs and parentAssocs.

Ex:  scriptNode.assocs["tr:relatedDocument"];// it gives you taget assoc map

For detial, please check - http://wiki.alfresco.com/wiki/4.0_JavaScript_API#ScriptNode_API

Hope it helps!

tytanix
Champ in-the-making
Champ in-the-making
Thank you very much! That works fine!