cancel
Showing results for 
Search instead for 
Did you mean: 

Solution: tag multiple files at once

zbennett
Champ in-the-making
Champ in-the-making
Hi all,

I've developed a very simple process for tagging multiple files at once. It relies on repository actions/rules and a couple lines of JavaScript, and it's all described below. Once you're all set up, you will be able to make a file inherit tags from a folder you move it into. My example is used for an Image Gallery, so my rule also moves files out of the tagged folders and back into the Image Gallery Document Library.

I am running Alfresco Community Edition v3.3 on my local machine and I am using the Alfresco Share interface.

——————————————-

First, we need to create a JavaScript file with a couple lines of code in it. This is easy, even for people who know nothing about JavaScript. How is it easy, you ask? It's easy because I'm going to tell you exactly what you need to do!

Open Notepad and copy the following code into your blank text file:
//Alfresco auto-tagger
//compliments of Zach Bennett, Eagle Productivity Solutions
//two lines of code
//free for anyone to use
//no license, no strings attached

//get tags from parent (folder) node
var tagArray = document.parent.getTags();

//add the tags to the document node
document.addTags(tagArray);

Now go to File -> Save As… Name your file "tagger.js" and save it to your desktop (or wherever you feel is appropriate). That's all there is to creating the JavaScript file, now we just need to upload it to Alfresco.

Go to your Repository
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/add_script/1_go_to_repo.jpg[/img]

Dive into the Data Dictionary
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/add_script/2_go_to_data_dict.jpg[/img]

And then into Scripts
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/add_script/3_go_to_scripts.jpg[/img]

Then just select Upload and browse to tagger.js (that JavaScript file you created)
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/add_script/4_click_upload.jpg[/img]

Now your script is ready to use! All that is left do is create a couple folders and a rule.

In this example, I created a folder called "auto-tagger" in my Image Gallery's Document Library. I then created a rule that runs the JavaScript code I wrote. My intention was to put temporary folders inside the auto-tagger folder, each with a set of tags that I could reuse over and over.

On the auto-tagger folder, select Manage Rules
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/1_select_manage_rules.jpg[/img]

Click Create Rules
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/2_click_create_rules.jpg[/img]

Give the rule a name, and make sure the check the 'Rule applies to subfolders' check box
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/3_name_and_rule_applies_to_subfolders.j...[/img]



*** Very important edit ***

You need to set the criteria so this rule only applies to Content items and NOT Folders (unless you want to make the same mistake I made!)
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/3andahalf_set_criteria.jpg[/img]


Under Perform Action, select Execute script
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/4_select_execute_script.jpg[/img]

And in the drop-down box that appears, you can now select tagger.js, which is the JavaScript file we created earlier
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/5_select_tagger.jpg[/img]

To make sure this folder stays empty (which was important for my purpose of an Image Gallery), we will add another action to the rule.

Click the plus symbol (+) to the right side of this rule
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/6_add_action.jpg[/img]

For this action, select Move
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/7_select_move.jpg[/img]

Then select where you want files to be moved to. I wanted files to be moved to the main Document Library of my Image Gallery site, but you may want to do things differently
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/8_select_location.jpg[/img]

And finally, click Create
[img]http://zandadev.com/zach/alfresco_auto_tag_guide/create_rule/9_click_create.jpg[/img]


Now that the rule is created (and applied to subfolders of auto-tagger), you can create folders inside of the auto-tagger folder and add tags to them. Once you do that, can can move files into (or upload directly to) those subfolders to make them inherit the appropriate tags. Any files created in or added to those subfolders will automatically be moved to the location you selected above (like my Image Gallery Document Library).


I hope this helps - happy tagging!
34 REPLIES 34

chops88
Champ in-the-making
Champ in-the-making
Wow. I'm so frustrated. Admittedly, I'm a sys admin, not a programmer, and I have very limited knowledge of java script. But I'm finding the documentation for the js API in alfresco to be obtuse AT BEST. I'm wondering if my installation/version - Community Share 4.0b is broken…

I'm running commands in the console just to see what works and what doesn't. (Most things don't work).

So this example command from the getTags documentation:


model.tags = taggingService.getTags("workspace://SpacesStore");
return (model.tags);

returns no errors (and no data).

This modification of the same command to include a real noderef


model.tags = taggingService.getTags("workspace://SpacesStore/eb01a162-f7ba-4e0b-a734-d0a7f98d1e9f");
return (model.tags);

Returns

01100038 Wrapped Exception (with status template): 01100854 Failed to execute script 'classpath*:alfresco/templates/webscripts/de/fme/jsconsole/execute.post.js': 01100853 No solr query support for store workspace://SpacesStore/eb01a162-f7ba-4e0b-a734-d0a7f98d1e9f

What the hell? And any reference to document.<anything> returns "document undefined".

How do you pull a current noderef, let alone a parent noderef and use it to find its tags?
The script the OP made is simple and logical. The javascript api in 4.0 seems to have abandoned simplicity, and possibly even logic.

mikeh
Star Contributor
Star Contributor
I've just tried the exact steps as described in the very first post on a 4.0 server and it worked perfectly.

Wow. I'm so frustrated. …
I think you're over-complicating things. Follow the steps in the first post exactly as they're written. Note the part about adding a title to the tagger.js script after it's been uploaded. Also, you're using an untested third-party add-on to try and run test script commands. I've absolutely zero experience with that component, but suspect it's the root cause of your frustrations.

Thanks,
Mike

chops88
Champ in-the-making
Champ in-the-making
Hmm - I did follow them exactly, and triple-checked when things weren't working. I certainly added a title to it too. It reports that it runs successfully. However, no tags are added to the content, either when added to the folder, or when running the rules on content already in the folder (although I'm not sure the latter would qualify for the rule to apply). Ive just installed 4.0d on a test server and will try it there to see if the results are different.

chops88
Champ in-the-making
Champ in-the-making
That's annoying. I just tried it now on a fresh install of 4.0d. Works perfectly. Guess I need to upgrade the production server… Thanks for the help, cheers.

bharat_bang
Champ in-the-making
Champ in-the-making
I am using Alfresco 3.4d
i want to tag the files with the names of the folder it is in.
Eg. if a file is in the folder hierarchy

Documents—>>>2011—>>>Audio—>>>>Actual File.mp3

then the "Actual File" should have tags "2011" , "Audio"
:roll:

And i want to apply these rules to a few thousand of documents which are imported by bulk importing a zipped file.

jebwhs87
Champ in-the-making
Champ in-the-making
I am using Alfresco Cloud v4.0.2 (Cloud 305) schema 5035 and I do not have the same select if all criteria are met rule items as listed in this article.  Have the rules changed since 4.0d (last post said it worked on that version)? Or is this a difference between cloud and cpu based?

nannasin28
Champ in-the-making
Champ in-the-making
feel free to post any related questions here!

tsonny
Champ in-the-making
Champ in-the-making
I applied this rule to a content folder, tagged the folder and now all items in the folder or added to the folder take the default tagging, great solution!

sbenedetti
Champ in-the-making
Champ in-the-making
Hi, and thank you for the script.

I've a problem using it with CIFS.

When I copy a file to a folder with the autotag script through CIFS, file is created empty (zero bytes).

Any idea?
Thank you

I found by myself.

The problem is related to the permission for the "Scripts" folder.
I removed EVERYONE from the Consumer role and the Scripts folder become inaccessible.

So adding a file to a folder with a rule is unable to trigger the script and fail to copy file.