IBM Support

Is there a sample JavaScript event action that is used to automatically configure security inheritance via the SecurityFolder property when a document is filed in a folder ?

Question & Answer


Question

Is there a sample JavaScript event action that is used to automatically configure security inheritance via the SecurityFolder property when a document is filed in a folder in FileNet Content Engine?

Answer

The following JavaScript code is solely provided as a sample without any expressed or implied warranty. It is used to create an asynchronous Event Action that is tied to a Subscription that triggers on the CheckIn event or OnCreate event.

When a document is checked in, the script retrieves the list of properties, specifically the FoldersFiledIn property.  If there are multiple folders, only the first one is retrieved.  It then sets the value of the Security Folder property to the folder retrieved.  Messages are also printed to SystemOut.log when the operation succeeds or fails to locate a folder or if it encounters an exception.

When the SecurityFolder property is set to a certain folder, any security at the folder level that is set to propagate to childen objects, will propagate to the respective documents with the Source field indicating 'Inherited' as opposed to 'Direct'.


importPackage(java.lang);
importClass(java.util.Iterator);
importClass(Packages.com.filenet.api.engine.EventActionHandler);
importClass(Packages.com.filenet.api.util.Id);
importPackage(Packages.com.filenet.api.events);
importPackage(Packages.com.filenet.api.property);
importPackage(Packages.com.filenet.api.security);
importPackage(Packages.com.filenet.api.core);
importPackage(Packages.com.filenet.api.constants);

importClass(java.lang.System);

function onEvent(event, subId)
{
      try {

      var oDoc, oProps, oRCR, oFolders, oFol, iter

      oDoc = Factory.Document.fetchInstance(event.getObjectStore(),event.get_SourceObjectId() ,null);
      oProps = oDoc.getProperties();
      oFolders = oProps.getIndependentObjectSetValue("FoldersFiledIn");
     
      iter = oFolders.iterator();

      if  (oFolders.isEmpty()) {
      System.out.println("Skipped Security Folder Document = " + oProps.getIdValue("ID").toString());
      }
      else {
      oFol= iter.next();
      oProps.putObjectValue ("SecurityFolder",oFol);
      oDoc.save (RefreshMode.REFRESH);
  System.out.println("Set SecurityFolder Document = " + oProps.getIdValue("ID").toString() + " , Folder = " + oFol.get_FolderName());
      }
      }
      catch (e) {
      System.out.println("Failed SecurityFolder Document = " + oProps.getIdValue("ID").toString());
      throw new RuntimeException(e);
      }

}

[{"Product":{"code":"SSNW2F","label":"FileNet P8 Platform"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Content 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.1;5.2;5.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
17 June 2018

UID

swg21695884