cancel
Showing results for 
Search instead for 
Did you mean: 

How to move duplicate document to a folder in alfresco community edition 5.2?

muqthar
Champ in-the-making
Champ in-the-making

Scenario:

I have to move Hellp.txt from Draft folder to Approved folder. First time it is working properly and sitting in the Approved folder but second time if i am trying move the updated same document second time then it is giving the following exception

org.alfresco.service.cmr.repository.DuplicateChildNodeNameException.

in this scenario, document name is same so it is giving this exception so we have to identify whether the approved folder has this document. if yes then delete that document and move the updated document else directly move the document to Approved folder.

if any web script available, please share with me. 

Thanks in advance.

Regards,

Muqthar

1 ACCEPTED ANSWER

jpotts
World-Class Innovator
World-Class Innovator

This is easily scripted. You should look at the Alfresco JavaScript API. In particular, you will probably want to look at the getChildByNamePath function on ScriptNode.

Try that out and let us know if you get stuck.

View answer in original post

6 REPLIES 6

jpotts
World-Class Innovator
World-Class Innovator

This is easily scripted. You should look at the Alfresco JavaScript API. In particular, you will probably want to look at the getChildByNamePath function on ScriptNode.

Try that out and let us know if you get stuck.

muqthar
Champ in-the-making
Champ in-the-making

Dear Jeff,

Thanks for your swift response.

We have written javascript and added as a rule (execute script) but the main problem is,

Move function is executing before our script so getting the same exception.

It will be helpful, if you provide any other alternate approach to achieve this.

Thanks in advance.

douglascrp
World-Class Innovator
World-Class Innovator

Are you talking about the Move action in the UI?

If that is the case, you can simply replace that by the move function using the javascript API.

Change the order with the existence check, and if everything is ok, then execute the move by code.

Something like:

if (document.properties["esc:semana"] &&
    document.properties["esc:ano"]) {

    var ano = document.properties["esc:ano"];
    var semana = document.properties["esc:semana"];

    var site = siteService.getSite(document.siteShortName);
    var doclib = site.getContainer("documentLibrary");

    var pastaAno = doclib.childByNamePath(ano);
    if (!pastaAno) {
        pastaAno = doclib.createFolder(ano);
    }

    var pastaSemana = pastaAno.childByNamePath(semana);
    if (!pastaSemana) {
        pastaSemana = pastaAno.createFolder(semana);
    }

    document.move(pastaSemana);
}

Notice that I am using both childByNamePath and move functions in the piece of code.

I hope you find this useful for your case.

muqthar
Champ in-the-making
Champ in-the-making

One more thought,

Can we use any existing aspects to achieve this?

douglascrp
World-Class Innovator
World-Class Innovator

What do you mean by existing aspects?

muqthar
Champ in-the-making
Champ in-the-making

Can anybody help me with this issue. Not able to move the document second time.