cancel
Showing results for 
Search instead for 
Did you mean: 

Duplicate Child Node Name Exception

patrik
Champ on-the-rise
Champ on-the-rise
Hi! I'm having a problem when using simple workflow and transformation from doc to pdf. I trigger the workflow to copy an item to another space where a rule says that the item should be transformed to pdf and copied to a space. This works fine the first time. But the second time i get this error:

ERROR [ui.common.Utils] Failed to approve the document due to system error: Duplicate child name not allowed: {filename}
org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: {filename}

Can't alfresco replace this file and update it with a new version? It doesn't matter if i delete the previous doc-file that was created if i keep the pdf. As long as any of the two files are left nothing happens besides the duplicate error. It works well when i replace the recently created doc-file in webdav. Then the pdf gets updated.

I use alfresco 2.1 Enterprise version.

Help appreciated
11 REPLIES 11

kevinr
Star Contributor
Star Contributor
The transform rule is pretty basic - you best bet is a JavaScript rule:
http://forums.alfresco.com/viewtopic.php?p=29257#29257

patrik
Champ on-the-rise
Champ on-the-rise
It seems to be the copy operation that doesn't support replacement (or update)

I've moved on to try to solve it with a javascript instead. The javascript first removes the file that is supposed to be replaced and then places the new transformed copy there instead. The problem that i have left is to set the version in accordance to the source object. I posted a thread on that here http://forums.alfresco.com/viewtopic.php?t=8806 .

schneika
Champ in-the-making
Champ in-the-making
Please can you post your complete javascript as an example here?

patrik
Champ on-the-rise
Champ on-the-rise
Here's the script. Now the version number is taken from the previous file. That means that i lose the version history. Is it possible to add a version to an existing node? E.g. by connecting the new file to the old one by workingCopyOwner and then check it in?

var document = search.findNode(args["node"]);
var space = document.parent;
var parentFolderName = space.properties.name;
var releasable;
var fileName = document.properties.name;
var fileNameBase = fileName.substring(0,fileName.length-4);
var reply;
var version=document.properties.versionLabel;

//Test if the document is releasable
if(document.hasAspect("cm:releasable"))
{
   releasable=document.properties.releasable;
}
else
{
   releasable=false;
}

if(releasable)
{
   var parentFolderParent=space.parent.parent;
   var destFolder = parentFolderParent.childByNamePath("Released/"+parentFolderName);
   
   //Remove current document if it exists
   var destFile = destFolder.childByNamePath(fileNameBase + ".pdf")
   if (destFile!=null)
   {
      destFile.remove();
   }
   
   //Transform and move the document
   var trans = document.transformDocument("application/pdf");
   var copy = trans.copy(destFolder);
   
   //Set version according to source document
   copy.addAspect("cm:versionable");
   copy.properties.initialVersion=false;
   copy.properties.versionLabel=version;
   copy.save();
   trans.remove();
   //reply="The document has been successfully released. Push the back button to return to Alfresco.";
   var goBack = "<script>history.back();</script>";
   goBack;
}
else
{
   reply="The document is not releasable. Push the back button to return to Alfresco.";
}

bjorn_r
Champ in-the-making
Champ in-the-making
Hi Patrik,

From 2.1 Enterprise and onwards there is a write method in the ScriptContent API, which is capable of copying binary content.

You should design your script to:
* Check out a working copy of your versioned node.
* Use the new write method to update the content of your working copy.
* Check in your working copy.

Cheers,
Björn

schneika
Champ in-the-making
Champ in-the-making
Perhaps anybody can give an example how to use this new write method in the ScriptContent-API of V2.1.0E and V2.2.0CE? A little script-snippet?

kevinr
Star Contributor
Star Contributor

// assume you have a document node called 'document' and that you have permissions to write to the current space

// first create a new node in the current space
var destNode = space.createFile("copy.txt");

// write the content from the current document into the destination
document.properties["cm:content"].write(destNode.properties["cm:content"]);

sacco
Champ in-the-making
Champ in-the-making

// write the content from the current document into the destination
document.properties["cm:content"].write(destNode.properties["cm:content"]);

Kevin, it looks as if you meant:

// write the content from the current document into the destination
destNode.content.write(document.properties.content);

The .write() method copies from its argument to the current node.

But what is the point of this method?  It create another file in the content
store on disk containing a copy of the content of the source, but with
Alfresco's  'write once' approach, there's surely no real point in storing
identical content in two different places … is there?

kevinr
Star Contributor
Star Contributor
The destination node may have different permissions i.e. may be accessable by different users. I'm sure you can think of other reasons why a copy of a content is useful Smiley Happy

Cheers

Kevin