IBM Support

JavaScript examples for handling bulk processing in Content Platform Engine

White Papers


Abstract

In the administration console, you can apply JavaScript bulk actions to the search results of an object store query. The JavaScript code examples that are shown here use the Content Platform Engine Java API and Java class libraries. You can use these libraries and JavaScript bulk actions to quickly write powerful scripts.

Content

The Content Platform Engine server uses the Mozilla Rhino scripting engine to execute the JavaScript.

Here are the prerequisites for running the JavaScript examples:

  • A Content Platform Engine 5.2.0 or later server is installed with a domain.
  • At least one object store is created.
  • Some documents with content exist in the object store.

Procedure overview

Downloading document content
This JavaScript example downloads the document content to a specified directory.

Forcing a promote event on a document
This JavaScript example demotes the major version of the document and then promotes a minor version.

Deleting a document
This JavaScript example deletes a document.

Fetching document properties
This JavaScript example fetches the document properties and prints the information.

Setting document properties
This JavaScript example shows how to update the document title property.


----------------------------------------------------------------------------------------------------------------------
Downloading document content
----------------------------------------------------------------------------------------------------------------------
This JavaScript example downloads the document content to a specified directory. Because the JavaScript code is executed on a Content Platform Engine server, the content download directory that you specify in the code must satisfy the following requirements:
  • It exists on the server
  • It is one to which the server has write permissions
Procedure

1. Open an object store and create an object store search.
2. On the SQL view tab, enter the following query:

SELECT TOP 100 This FROM Document

3. Select Enable bulk action on the bulk action tab.
4. In the Script section, click Run script.
5. Copy the following JavaScript code and paste it into the Script field:

importClass(Packages.com.filenet.api.collection.ContentElementList);
importClass(Packages.com.filenet.api.core.ContentTransfer);
importClass(java.io.FileOutputStream);
importClass(java.io.InputStream);
importClass(java.lang.Byte);

function OnCustomProcess (CEObject)
{
   CEObject.refresh();
   var ce = CEObject.get_ContentElements();
   if(ce.size() > 0)
   {
     var ct = ce.get(0);
     var folderName = "C://Temp/Content/";
     this._downloadContent(folderName, ct);
  }
}

function _downloadContent(folderName, ct)
{
   var out = new FileOutputStream(folderName + ct.get_RetrievalName());
   var docLen = ct.get_ContentSize().intValue();
   var buf = java.lang.reflect.Array.newInstance(Byte.TYPE, docLen)
   var stream = ct.accessContentStream();

   stream.read(buf, 0, docLen);
   out.write(buf);
   out.flush();
   stream.close();
   out.close();
}

6. Change the output directory in the script. Verify that this download directory exists on the Content Platform Engine server.
7. Click Run. The administration console runs the query and the JavaScript action.
8. After the query runs, look at the output folder to verify that the document content was downloaded as expected.


----------------------------------------------------------------------------------------------------------------------
Forcing a promote event on a document
----------------------------------------------------------------------------------------------------------------------
This JavaScript example demotes the major version of the document and then promotes a minor version.

Procedure

1. Open an object store and create an object store search.
2. On the SQL view tab, enter the following query:

SELECT TOP 5 This FROM Document

3. Select Enable bulk action on the bulk action tab.
4. In the Script section, click Run script.
5. Copy the following JavaScript code and paste it into the Script field:

importClass(Packages.com.filenet.api.constants.RefreshMode);

function OnCustomProcess (CEObject)
{
   CEObject.demoteVersion();
   CEObject.save(RefreshMode.REFRESH);
   CEObject.promoteVersion();
   CEObject.save(RefreshMode.REFRESH);
}

6. Click Run. The administration console runs the query and the JavaScript action.


----------------------------------------------------------------------------------------------------------------------
Deleting a document
----------------------------------------------------------------------------------------------------------------------
This JavaScript example deletes a document.

Important: Create a document with a document title such as “Test Delete Document”.

Procedure

1. Open an object store and create an object store search.
2. On the SQL view tab, enter following query:

SELECT This FROM Document WHERE DocumentTitle = 'Test Delete Document'

3. Select Enable bulk action on the bulk action tab.
4. In the Script section, click Run script.
5. Copy the following JavaScript code and paste it into the Script field:

importClass(java.lang.System);
importClass(Packages.com.filenet.api.property.Properties);
importClass(Packages.com.filenet.api.constants.RefreshMode);

function OnCustomProcess (CEObject)
{
   System.out.println("Executing Delete Document script");
   CEObject.delete();
   CEObject.save(RefreshMode.REFRESH);
   System.out.println("Document deleted successfully");
}

6. Click Run. The administration console runs the query and the JavaScript action.


----------------------------------------------------------------------------------------------------------------------
Fetching document properties
----------------------------------------------------------------------------------------------------------------------
This JavaScript example fetches the document properties and prints the information. This information is logged in an application log file.

Procedure

1. Open an object store and create an object store search.
2. On the SQL view tab, enter the following query:

SELECT TOP 5 This FROM Document

3. Select Enable bulk action on the bulk action tab.
4. In the Script section, click Run script.
5. Copy the following JavaScript code and paste it into the Script field:

importClass(java.lang.System);
importClass(Packages.com.filenet.api.property.Properties);

function OnCustomProcess (CEObject)
{
   System.out.println("Executing Fetch Properties script");
   CEObject.refresh();
   var props = CEObject.getProperties();

   System.out.println("ClassName................... "
     + CEObject.getClassName());
   System.out.println("Has DocumentTitle property.. "
     + props.isPropertyPresent("DocumentTitle"));
   System.out.println("Propertites size............ "
     + props.size());
}

6. Click Run. The administration console runs the query and the JavaScript action.


----------------------------------------------------------------------------------------------------------------------
Setting document properties
----------------------------------------------------------------------------------------------------------------------
This JavaScript example shows how to update the document title property.

Procedure

1. Open an object store and copy the Id of the document that you want to change.
2. Create an object store search.
3. On the SQL view tab, enter the following query with the appropriate document Id:

SELECT This FROM Document WHERE Id = <Document-Id>

4. Select Enable bulk action on the bulk action tab.
5. In the Script section, click Run script.
6. Copy the following JavaScript code and paste it into the Script field:

importClass(Packages.com.filenet.api.property.Properties);
importClass(Packages.com.filenet.api.constants.RefreshMode);

function OnCustomProcess (CEObject)
{
   CEObject.refresh();
   CEObject.getProperties().putValue("DocumentTitle", "Test1");
   CEObject.save(RefreshMode.REFRESH);
}

7. Click Run. The administration console runs the query and the JavaScript action.

[{"Product":{"code":"SSNVNV","label":"FileNet Content Manager"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Content Platform Engine","Platform":[{"code":"PF033","label":"Windows"},{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"}],"Version":"5.2.0","Edition":"All Editions","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSGLW6","label":"IBM Content Foundation"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Content Platform Engine","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"5.2.1;5.2","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
17 June 2018

UID

swg27043998