Change the file name Alfresco

825 views Asked by At

I need to change the name of the file attached to the workflow and move to another location during the execution. The file name is generated based on the information entered in the form of process (Registration Number field and Sender). How can this be implemented? Thanks!

For example: BX-2/Nick_Berry.xls

Screen

3

There are 3 answers

0
Tackle Berry On BEST ANSWER

I am find own solution this issue. Need to create execution listener in user task. Its code is:

<extensionElements>
                    <activiti:executionListener class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener" event="start">
                        <activiti:field name="script">
                            <activiti:string><![CDATA[    

                               if (typeof execution.getVariableLocal('zvernennya_registrationnumber') != undefined) execution.setVariable('zvernennya_registrationnumber', execution.getVariableLocal('zvernennya_registrationnumber'));    
                               if (typeof execution.getVariableLocal('zvernennya_sender') != undefined) execution.setVariable('zvernennya_sender', execution.getVariableLocal('zvernennya_sender'));        
                                 for (var i = 0; i < bpm_package.children.length; i++) {
                                    var child = bpm_package.children[i];   
                                        a = child.properties['cm:name'].split('.'); 
                                        var ext = a[a.length-1];   

                                        child.properties['cm:name']=zvernennya_registrationnumber+" "+zvernennya_sender+"."+ext;                  
                                        child.save();
                                }
                            ]]></activiti:string>
                        </activiti:field>
                    </activiti:executionListener>
            </extensionElements>
0
billerby On

The file is attached to the workflow as the execution scope variable bpm:package (ie a secondary child association). You should be able implement a EndTaskListener that grabs the form info from the task scope and finds out the parent of the bpm:package and then rename the parent.

0
Stefan De Laet On

You will need to write a (java) listener that will run when the form has been completed and the task will end.
Here is how to get the NodeRef of your file from your workflow execution context:

    public NodeRef getFirstPackageItem(DelegateExecution execution){
    ActivitiScriptNode packageItemsbpm = (ActivitiScriptNode) execution.getVariable("bpm_package");
    try {
        if (packageItemsbpm != null && packageItemsbpm.getHasChildren()){
            return nodeService.getChildAssocs(packageItemsbpm.getNodeRef()).get(0).getChildRef();
        }
    } catch (Throwable e) {
        logger.error("",e);
    }
    return null;
}

Setting the name out of the form propery values is done by getting the values from your task object, and storing them on your NodeRef:

NodeRef file = getFirstPackageItem(execution)
Object filenameprefix = task.getVariable("mymodel_regnumber");
Object filenamesuffix = task.getVariable("mymodel_sender");
nodeService.setProperty(file, ContentModel.PROP_NAME, filenameprefix+"/"+filenamesuffix );