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.
Solved! Go to Solution.
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 !
Implement a folder rule or Implement a behavior which can listen to onCreateNode event and moves the files by creating the folder based on available metadata. With bevahior implementation, you get more control over the operation.
When the file will be uploaded, this behavior will trigger as soon as onCreateNode event is issues and does the required job. Your logic will go into onCreateNode method which you would implement for NodeServicePolicies.OnCreateNodePolicy
/* (non-Javadoc) * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy#onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef) */ @Override public void onCreateNode(final ChildAssociationRef childAssocNode) { //Your logic goes here. } } }
Refer this documentation on creating the behavior:
https://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html
https://docs.alfresco.com/5.2/references/dev-extension-points-behaviors.html
Thank you abhinavmishra14 !
I just start on java and if possible, i would like to not use web script (i'm more than a noob with it)
Actually my script look like this and is executed by rules in a folder :
var Descr = document.properties["test:BDC-SEDIT-propriete"]; var myfolder = userhome.createFolder(Descr);
this is the catalina log :
Caused by: org.alfresco.service.cmr.model.FileExistsException: 10194109 Le fichier ou dossier 19005114 existe déjà
It's french and it mean that the folder already exist.
19005114 is the propertie name i want to have fore the folder.
It already exist because 2 files get the same metadata so my script try to create 2 time the same file.
Now i want a condition that if it exist, so it create the folder and push the X documents who have same metadata into the folder.
Thank by advance !
The same folder, not the same file sorry
Hello,
It seems that you are looking for something like that:
var Descr = document.properties["test:BDC-SEDIT-propriete"]; var myfolder = userhome.childByNamePath(Descr); if (myfolder === null) { myfolder = userhome.createFolder(Descr); } document.move(myfolder);
Regards,
Thank you very much !
It nearly work as i want to.
Except that it move the folder in my share/user folder.
This script is set for a Site.
var Descr = document.properties["test:BDC-SEDIT-propriete"]; var myfolder = userhome.childByNamePath(Descr); if (myfolder === null) { myfolder = userhome.createFolder(Descr); } document.move(myfolder);
I just have to change the red command to set it on the same folder.
Explaination :
I have the files with that metadata on share site folder alfresco\share\page\Sites\BDC\BC_INFO\
I need that the script create the folder in this node :
alfresco\share\page\Sites\BDC\BC_INFO\"Descr"
Again, thank you very much for you help roberto_gamiz
Hello,
To execute the process in the same folder just change the line
var myfolder = userhome.childByNamePath(Descr);
for
var parent = document.parent; var myfolder = parent .childByNamePath(Descr);
Regards
Thank you again to take care about me !
Here is the code for now :
var Descr = document.properties["test:BDC-SEDIT-propriete"]; var parent = document.parent; var myfolder = parent.childByNamePath(Descr); if (myfolder === null) { myfolder = parent.createFolder(Descr); } document.move(myfolder);
But script failed
Caused by: java.lang.NullPointerException: Illegal null path
I didn't paste all the javalog to not spam, but i can if you need all logs
I think you need to add some integrity checks to your code.
For example before start the process you need to ensure that the property "test:BDC-SEDIT-propriete" have a value not equals to null and that the code is not executed for a content of folder type.
Regards.
Hi,
Thanks for you reply.
I put only files who contain "test:BDC-SEDIT-propriete" value.
And i still have the same error.
I add in the alfresco's rules to not execute if the "test:BDC-SEDIT-propriete" = null
I still have the same error.
When i use the script with this code value
var Descr = document.properties["test:BDC-SEDIT-propriete"];
var parent = document.parent;
var myfolder = parent.childByNamePath(Descr);
if (myfolder === null) {
myfolder = userhome.createFolder(Descr);
}
document.move(myfolder);
It work and move folders/files correctly on my user's folder.
We are so close to adjust it, do you think that "document.parent" is not the good command ?
var parent = document.parent; var myfolder = parent.childByNamePath(Descr);
I just suppose because i'm not expert at all.
By advance thank you again !
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.