Add labels through javascript

cancel
Showing results for 
Search instead for 
Did you mean: 
patrickvanhoof
Customer

Add labels through javascript

Jump to solution

I have following situation: a whole lot of files and folders are now stored on a drive. We want to migrate those to Alfresco, and add the same time add the correct labels. Problem is that labels can not be assigned based on the folder structure, so a rule is no option.

What I think should be possible is the following:

  • the names of the current files need to updated anyhow, so in some way we could the needed labels at the end of the file names, separated with e.g. a $
  • the files are uploaded to Alfresco
  • a javascript has to be run that extracts the labels from the file names and add these as labels to the corresponding document
  • the javascript at the same time removes the labels from the file names

Is there a better or more efficient way to do this?

What javascript command has to be used to extract labels from the file name?

Thanks,

Patrick

1 Solution

Accepted Solutions
mehe
Senior Member II

Re: Add labels through javascript

Jump to solution

I think you are talking about "tags". You can add these tags - that show up as a kind of "labels" in alfresco share using node.addTag(Tarnname) - you were quite close:

Tagging API | Alfresco Documentation 

View solution in original post

4 Replies
mehe
Senior Member II

Re: Add labels through javascript

Jump to solution

Assuming you have a directory structure on a fileserver, want to import the whole structure and add metadata based on the Path of the imported documents, you have several optinons:

- copy it over on the alfresco servers filesystem, create metadata xml files and use the bulk importer Using the Bulk Import tool | Alfresco Documentation 

- copy it to alfresco by webDav and use a rule to add the metadata. You can trigger a javascript by rule "onCreate" in a folder and all it subfolders. In your script, make sure the triggering object is a file (document.isDocument) and extract the data from document.displayPath

patrickvanhoof
Customer

Re: Add labels through javascript

Jump to solution

I'll have a look at the metadata xml and bulk import.

A rule is not possible, the place of the files in the structure does not determine the labels. So we somehow have to add the labels via another way.

patrickvanhoof
Customer

Re: Add labels through javascript

Jump to solution

One more question: assume we are going for a rule on a folder that adds a specific label to the files loaded in that folder, which javascript command is used to add that label to a document? Is it someting like node.addLabel(labelname)?

mehe
Senior Member II

Re: Add labels through javascript

Jump to solution

I think you are talking about "tags". You can add these tags - that show up as a kind of "labels" in alfresco share using node.addTag(Tarnname) - you were quite close:

Tagging API | Alfresco Documentation