The IBM FileNet Content Platform Engine server uses the Mozilla Rhino scripting engine to execute the JavaScript.
Prerequisites for running the JavaScript examples: Content Platform Engine 5.2.0 or later
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 exists on the CPE server and should have write permissions
Procedure
- Open an object store and create an object store search.
- On the
SQL view tab, enter the following query:
SELECT TOP 100 This FROM Document
- Select Enable bulk action on the bulk action tab.
- In the Script section, click Run script.
- 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 = "D://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();
}
- Click Run. The administration console runs the query and the JavaScript action.
Deleting a document
- Open an object store and create an object store search.
- On the
SQL view tab, enter following query:
SELECT This FROM Document WHERE DocumentTitle = '<Criteria>'
- Select Enable bulk action on the bulk action tab.
- In the Script section, click Run script.
- 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");
}
- Click Run.
Fetching document properties
- Open an object store and create an object store search.
- On the
SQL view tab, enter the following query:
SELECT TOP 5 This FROM Document
- Select Enable bulk action on the bulk action tab.
- In the Script section, click Run script.
- 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
Setting document properties
- Open an object store and copy the Id of the document that you want to change.
- Create an object store search.
- On the
SQL view tab, enter the following query with the appropriate document Id:
SELECT This FROM Document WHERE Id = <Document-Id>
- Select Enable bulk action on the bulk action tab.
- In the Script section, click Run script.
- 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);
}
- Click Run
Promote event on a document
- Open an object store and create an object store search.
- On the
SQL view tab, enter the following query:
SELECT TOP 5 This FROM Document
- Select Enable bulk action on the bulk action tab.
- In the Script section, click Run script.
- 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);
}
- Click Run