Custom Association
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2013 11:47 AM
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.
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.
Labels:
- Labels:
-
Archive
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2013 01:21 AM
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!
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!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2013 07:52 AM
Thank you very much! That works fine!
