cancel
Showing results for 
Search instead for 
Did you mean: 

Duplicate content after simple workflow

ejml
Champ in-the-making
Champ in-the-making
I have the next issue:

1) I create the first space -> Approved
2) I create a rule -> add aspect versionable on first space.
3) I create te second space -> pending to approve.
4) I create a rule -> simple workflow to move at the first folder.

When I have a document with the name test.txt and I approve, it's work fine, it's moved from first folder to second folder. When I have other document on first folder with the same name that the previous document, and I approve this document, surprise!!, now I have TWO documents with the same name on the second folder.

Could I make some script to fix it?

Thanks
7 REPLIES 7

ejml
Champ in-the-making
Champ in-the-making
I have tried this:

var FilesInSpaces = space.childrenByXPath("*[@cm:name='" + document.name + "']/*");
var NodoAux;

for(int i=0; i<FilesInSpaces.properties.size; i++) {
   NodoAux = FilesInSpaces;
   if(NodoAux!=document && NodoAux.isDocument())
      NodoAux.remove();
}

But it return the next error's message:

Transaction didn't commit: Failed to execute script 'workspace://SpacesStore/49b4e24a-17fc-11db-b3b0-0b9dee52ab00': identifier is a reserved word (AlfrescoScript#10)

anweber
Champ in-the-making
Champ in-the-making
Hi,

   I propose you the following solution.


   I have created this folder structure :

  • f1
    • toMoveToF2
  • f2
In the folder "f1", I have defined a rule that attachs a simple workflow to move the current file to the folder "toMoveToF2".
In the folder "toMoveToF2", I have defined a rule that will execute the following script :

var targetFolderPath = "aweTests/moveTest/f2";


var docName;
var targetFolder;
docName = document.name;
targetFolder = companyhome .childByNamePath(targetFolderPath);
if (targetFolder .childByNamePath(docName)!=null){
   document.remove();
} else {
   document.move(targetFolder);
}


This script controls if a file with the same name already exists in the target folder.  If yes, the new file is not move but deleted (if you prefer, you could easely change this code to replace the file in the target folder : delete oldFile, move newFile).

          Regards,

                    Andre

ejml
Champ in-the-making
Champ in-the-making
I need to replace the file in the target folder. Could it be something so?:

var targetFolderPath = "aweTests/moveTest/f2";


var docName;
var targetFolder;
var oldDocument;
docName = document.name;
targetFolder = companyhome .childByNamePath(targetFolderPath);
oldDocument = targetFolder .childByNamePath(docName)

if (oldDocument !=null){
   oldDocument.remove();

document.move(targetFolder);
}

anweber
Champ in-the-making
Champ in-the-making
Exactly (expect that you have also to do "document.move()" if oldDocument == null).

I have tested this code :


var targetFolderPath = "moveTest/f2";


var docName;
var targetFolder;
var oldDocument;

docName = document.name;
targetFolder = companyhome.childByNamePath(targetFolderPath);

oldDocument = targetFolder.childByNamePath(docName)

if (oldDocument !=null){
   oldDocument.remove();
}

document.move(targetFolder);




    Regards,

              Andre

ejml
Champ in-the-making
Champ in-the-making
It's possible to pass the targetFolderPath as parameter?.

Thanks

anweber
Champ in-the-making
Champ in-the-making
No, you can't pass the target folder as argument to the execution of this script.  Instead, you could use the name of the intermediary folder or the value of a property of your document (you should then apply a custom subtype or a custom aspect to your document).

An alternative solution is to use an HTML form to submit your request to move, then you use the command servlet to execute your script and you have the possibilty to transfer arguments (like the name of target folder).  See http://forums.alfresco.com/viewtopic.php?t=2555

            Regards,

                  Andre

ejml
Champ in-the-making
Champ in-the-making
Very thanks Andre, very thanks.