cancel
Showing results for 
Search instead for 
Did you mean: 

create folder with document.properties and push files into this folder

castelsarrasin
Confirmed Champ
Confirmed Champ

 Hi !

I have Alfresco community 5.2f

How can i create folder containing the name of some properties and push the files who get the same properties value in this new folder ?

Exemple :

File 1 have properties-test= XXX

File 2 have properties-test= XXX

then create folder "XXX" 

then push those files in "XXX" folder

Tell me what you need to know to help me, i'll answer.

2 ACCEPTED ANSWERS

Hello,

You are receiving that null pointer error because you are passing a null value to the function childByNamePath.

I think this happens beacause the rule is executed for the subfolders that are created in the process, i'm not sure that the condition with null in the rule definition work properly in this case.

Try to add a condition in the rule definition for only execute the rule for documents and add the null comparation in the script code. 

Regards

View answer in original post

It work !!!

Thank you !!!!

I just add in the rule the condition as you expected :

If in the content "BDC-SEDIT-propriete" have "XXX" (XXX = number of the metadata)

The good java command for people who needed the same as me :

var Descr = document.properties["alah:BDC-SEDIT-propriete"];
var parent = document.parent;
var myfolder = parent.childByNamePath(Descr);
if (myfolder === null) {
    myfolder = parent.createFolder(Descr);
}
document.move(myfolder);

To finally add some more features ine the folder's name with more metadata it look like this 

var Descr = document.properties["test:BDC-SEDIT-propriete"];
var libelle =  document.properties["test:BDC-SEDIT-ObjetCommande"];
var tiers =  document.properties["test:BDC-SEDIT-LibelleTiers"];
var parent = document.parent;
var myfolder = parent.childByNamePath(Descr + "_" + tiers + "_" + libelle);
if (myfolder === null) {
    myfolder = parent.createFolder(Descr + "_" + tiers + "_" + libelle);
}
document.move(myfolder);

With this, the folder name look like this : "BDC-SEDIT-propriete_BDC-SEDIT-ObjetCommande_BDC-SEDIT-LibelleTiers"

Roberto you ownz ! if you send me private message with your postal adress i'll send you french wine ! Promise !

View answer in original post

11 REPLIES 11

Hello,

You are receiving that null pointer error because you are passing a null value to the function childByNamePath.

I think this happens beacause the rule is executed for the subfolders that are created in the process, i'm not sure that the condition with null in the rule definition work properly in this case.

Try to add a condition in the rule definition for only execute the rule for documents and add the null comparation in the script code. 

Regards

It work !!!

Thank you !!!!

I just add in the rule the condition as you expected :

If in the content "BDC-SEDIT-propriete" have "XXX" (XXX = number of the metadata)

The good java command for people who needed the same as me :

var Descr = document.properties["alah:BDC-SEDIT-propriete"];
var parent = document.parent;
var myfolder = parent.childByNamePath(Descr);
if (myfolder === null) {
    myfolder = parent.createFolder(Descr);
}
document.move(myfolder);

To finally add some more features ine the folder's name with more metadata it look like this 

var Descr = document.properties["test:BDC-SEDIT-propriete"];
var libelle =  document.properties["test:BDC-SEDIT-ObjetCommande"];
var tiers =  document.properties["test:BDC-SEDIT-LibelleTiers"];
var parent = document.parent;
var myfolder = parent.childByNamePath(Descr + "_" + tiers + "_" + libelle);
if (myfolder === null) {
    myfolder = parent.createFolder(Descr + "_" + tiers + "_" + libelle);
}
document.move(myfolder);

With this, the folder name look like this : "BDC-SEDIT-propriete_BDC-SEDIT-ObjetCommande_BDC-SEDIT-LibelleTiers"

Roberto you ownz ! if you send me private message with your postal adress i'll send you french wine ! Promise !