27 September 2010
Some experience with using LiveCycle Contentspace ES2 will be helpful.
Beginning
When multiple people are uploading content to Adobe LiveCycle Contentspace ES2 sometimes it can be difficult to avoid name conflicts. To avoid the unnecessary hassle of finding a new name for the document you can easily write some simple scripts that will take care of name conflicts for you automatically.
In this article, I’ll cover how to create a simple rule that will be applied on all documents when they are uploaded in the space where the rule is implemented. This rule will simply execute a script that will do the automatic numbering of the document and store the number as the name of the document. If you want to keep the original name of the document then you can simply prefix or append the number generated by the script to the original name.
Follow these steps to create a new content rule in LiveCycle Contentspace ES2:

When a script is executed on a document, it is available as an object named document, which can be used in the script. The current name of the file is available as document.name.
There are several ways of generating a random number to use in creating a unique name for the document. The script below uses the row id of the document. Every document uploaded to Contentspace is stored in database and is exposed to the document as a property.
Because there can be errors, it’s a good practice to ensure that the upload was successful, so the code below verifies that the file exists in the space before attempting to rename it.
var filename = document.name;
if(filename != null && filename != undefined)
{
// uploaded file retrieved from space just to make sure that file was
// uploaded without error.
var newfile = space.childByNamePath(filename);
var newName = "Doc";
var dbid;
var fileext = ".xml";
if (newfile != null )
{
//Get the Row Id of the document currently uploaded.
dbid = newfile.properties[
"{http://www.alfresco.org/model/system/1.0}node-dbid"];
if(dbid != null)
{
// Find the extension of the file
var dotIndex = filename.lastIndexOf(".");
if(dotIndex > 0)
{
fileext = filename.substring(dotIndex);
}
document.name = newName + dbid + fileext;
//save the document
document.save();
}
}
}
You can modify this script to implement different naming conventions based on the type of the file. For example, if the file is an XML, DOC, or TXT file, you could use a format such as DocXXX. If it is an image (a JPG for example) you could use ImgXXX.
For more details on content rules, see Getting Started with LiveCycle Contentspace ES2 .

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License