cancel
Showing results for 
Search instead for 
Did you mean: 

(Javascript) business rules for bulk uploads

leifuss
Champ in-the-making
Champ in-the-making
Hi

I'm trying to implement a dropbox system using javscripts triggered by business rules. (It seems a lot quicker and easier to manage that way than to create a rule for each action). The main problem that I am facing at the moment is with bulk uploads (generally via CIFS).

when faced with a directory the business rule will only be run over the directory itself, not the contents - I can handle this with simple iterative loop over its children, and this works fine if I execute the script on content that is already in Alfresco. If I trigger it on the point of entry however, Alfresco is still only aware of the parent node, so a call to
container.children.length
returns 0 (i.e. it is an empty array). That means that I can only apply metadata etc. to the directory itself and not its contents.

I could presumablyuse a cron job as a workaround but it would be much more efficient (and intuitive for users) to run it at the point of import. Has anyone found a way to do this?

Many thanks,
Leif
5 REPLIES 5

leifuss
Champ in-the-making
Champ in-the-making
As an addendum to this, is it possible to create a versioned update of a binary file via javascript? Trying to copy over it throws an exception and setting the document.content old file from that of the new file seems dodgy as it uses a character (rather than binary) stream.

L.

kevinr
Star Contributor
Star Contributor
As an addendum to this, is it possible to create a versioned update of a binary file via javascript? Trying to copy over it throws an exception and setting the document.content old file from that of the new file seems dodgy as it uses a character (rather than binary) stream.

Correct yes it was designed for just dealing with text based content.

We have added a new API for this, but it only made it into the 2.1Enterprise codeline - it will be merged over to the HEAD code stream shortly.

http://wiki.alfresco.com/wiki/JavaScript_API#ScriptContent_API
see the write() method.

Thanks,

Kevin

leifuss
Champ in-the-making
Champ in-the-making
Great - thanks Smiley Happy

When does 2.1 enterprise become available? And (as if that weren't helpful enough!) any thoughts on the directory import problem?

Cheers

L.

kevinr
Star Contributor
Star Contributor
By the end of the week in theory, but i'm not signing anything Smiley Happy

I think the problem you are seeing with the empty array is a known issue with CIFS. Due to the way the CIFS protocol works, the creation of each item such as a folder or a file is a separate transaction. So at the point at which the rule is fired for the parent folder creation, the children have not yet actually been created - so the zero length array is correct. I suggest you try a rule that fires when each document is added and process each item in turn. It's annoying but it's amazing something as crazy as CIFS works in Java at all Smiley Wink

Thanks,

Kevin

leifuss
Champ in-the-making
Champ in-the-making
Thanks again

I'll keep an eye out for 2.1E and in the meantime I'll try a polling approach with the directories and post back to the forum with how I get on.

L.