FileNet P8 Content Engine, Version 4.0.+              

File document handler

This handler files a document to a specified folder, determined by the event fired on the document.

File document handler
Content Engine 3.5.x JScript Version
function OnEvent (Event, Subscription) 
{ 
var doc = Event.SourceObject; 
if (Event.IsOfClass("CreationEvent")) 
{ 
FileDocInFolder("/Docs", doc); 
} 
else if (Event.IsOfClass("ChangeClassEvent")) 
{ 
FileDocInFolder("/Archives", doc); 
} 
} 
function FileDocInFolder(otherFolderName, doc) 
{ 
var os = doc.ObjectStore; 
var rootFld = os.RootFolder; 
var fldSet = new Enumerator(rootFld.SubFolders); 
var subFld; 
for (; !fldSet.atEnd(); fldSet.moveNext()) 
{ 
subFld = fldSet.item(); if (subFld.Name == otherFolderName) 
{ subFld.File(doc, 0, doc.DocumentTitle);
 }
 }
 } 
Content Engine 4.x Java Version
import com.filenet.api.constants.*; 
import com.filenet.api.constants.DefineSecurityParentage; 
import com.filenet.api.core.*; 
import com.filenet.api.engine.EventActionHandler; 
import com.filenet.api.events.ObjectChangeEvent; 
import com.filenet.api.exception.EngineRuntimeException; 
import com.filenet.api.exception.ExceptionCode; 
import com.filenet.api.util.Id; public class FileDocumentAction implements 
EventActionHandler { 

public void onEvent(ObjectChangeEvent event, Id subscriptionId) throws 
EngineRuntimeException 
{ 
Document doc = (Document)event.get_SourceObject(); 
try 
{ 
if (event.getClassName().equalsIgnoreCase("CreationEvent")) 
FileDocInFolder("/docs", doc); 
else if (event.getClassName().equalsIgnoreCase("ChangeClassEvent")) 
FileDocInFolder("/Archives", doc); 
} 
catch (Exception e) 
{ 
throw new EngineRuntimeException(ExceptionCode.E_FAILED); 
} 
}  
public void fileDocInFolder(String folderName, Document doc) 
{ 
try 
{ 
Folder folder = (Folder)doc.getObjectStore().getObject("Folder", folderName); 
ReferentialContainmentRelationship rel = folder.file (doc, 
AutoUniqueName.AUTO_UNIQUE, doc.get_Name(), 
DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE); 
rel.save(RefreshMode.NO_REFRESH); 
} 
catch (Exception e) 
{ 
e.printStackTrace(); 
} 
} 
} 


Feedback

Last updated: November 2010


© Copyright IBM Corporation 2010.
This information center is powered by Eclipse technology. (http://www.eclipse.org)