Table of contents


27 September 2010


Prerequisite knowledge

Some experience with using LiveCycle Contentspace ES2 will be helpful.

User level


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.

Step 1: Create a rule

Follow these steps to create a new content rule in LiveCycle Contentspace ES2:

  1. Login to LiveCycle Contentspace ES2 and open the space you want to work with.
  2. Click More Actions > Manage Content Rules, and then click Create Rule to open the Create Rule Wizard.
  3. In the Select Conditions section specify the content that the rule will affect. If you want all content types to be indexed then select All Items, otherwise select as required based on type, name, and so on. You can define multiple conditions. Click Next.
  4. In the Select Actions section, select Execute A Script. When you select this option all scripts in the Data Dictionary / Scripts space will be available. Here you need to name the script that you will create in Step 2 below. For example if you name your script ContentRename.js, you would specify that here. Click Next.
  5. In the Enter Details section select Inbound as the Type so that the rule will be invoked on inbound content. Type a title and description for the rule; for example type Rename for both. You may select the option to apply the rule to sub spaces if that is appropriate. Click Next.
  6. Verify the summary of the new rule (see Figure 1) and click Finish.

Step 2: Create a script

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

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 =; 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 =[ "{}node-dbid"]; if(dbid != null) { // Find the extension of the file var dotIndex = filename.lastIndexOf("."); if(dotIndex > 0) { fileext = filename.substring(dotIndex); } = newName + dbid + fileext; //save the document; } } }

Where to go from here

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.