cancel
Showing results for 
Search instead for 
Did you mean: 

Association to specific version on another node

kokachev
Champ in-the-making
Champ in-the-making
Dear All.
I've created custom model and I'd like to create association with specific version of another node.
Is this possible? If so, could someone please advise on how to achieve that?

So far, association point to working copy of node, which is not what I want.

Thanks in advance.
4 REPLIES 4

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Hi kokachev,

I guess you will have to code it by getting the nodeRef of the version you want to create the association to.

You could do it using the VersionService if you know the version or you could run through the versionHistory and get the one you want.


VersionHistory versionHistory = versionService.getVersionHistory(nodeRef);

Version version = null;

if(myVersionString != null && !myVersionString.equals(""))
{
   //if you know the version
   version = versionHistory.getVersion(myVersionString);
}
else
{
   for(Version currentVersion : versionHistory.getAllVersions)
   {
      if(… whatever your condition is …)
      {
         version = currentVersion;
         break;
      }
   }
}

if(version != null)
{
   // Get the nodeRef of the version
   NodeRef versionNodeRef = version.getFrozenStateNodeRef();

   // Create the association
}

I must say I've never tried doing so… so I don't know if there will be any policy of permission issues…

Regards,
Adei

kokachev
Champ in-the-making
Champ in-the-making
Thanks Adei.
Could you please advise on how/when this script should be called? (sorry, I'm new to Alfresco)

My idea was to select association in Share, in edit properties. So user suppose to press "Edit properties", then press "Select" button
and choose related files.

Thanks.

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Oh that is java…

You would have to do quite few changes for that…. Check the association control out, it has some parameters to be configured but no one will help you… You'll need to hack it

You can otherwise create your own control…

Adei

Hi,
As per your answer above @amandaluniz_z ,you are suggesting to modify the versioned node refrence and make an association with it.
But that is not possible as all versioned node refrences are read only and doing so will get you an error. sumthing like this

/*
<strong>java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.</strong>
*/

So, I think you have no other option than to fetch individual versions of each node and somehow set up an relationship amongst them.unless u find some other workaround to modify/update versioned nodes.