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

cancel
Showing results for 
Search instead for 
Did you mean: 
muqthar
Member II

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

Jump to solution

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 Solution

Accepted Solutions
jpotts
Professional

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

Jump to solution

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 solution in original post

6 Replies
jpotts
Professional

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

Jump to solution

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
Member II

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

Jump to solution

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.

muqthar
Member II

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

Jump to solution

One more thought,

Can we use any existing aspects to achieve this?

muqthar
Member II

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

Jump to solution

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

douglascrp
Advanced II

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

Jump to solution

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.

douglascrp
Advanced II

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

Jump to solution

What do you mean by existing aspects?