IBM Support

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

Technical Blog Post


Abstract

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

Body

You can configure a document or custom object to inherit permissions from a folder using the Security Folder property.  The manual instructions are included in the P8 knowledge center:  https://www.ibm.com/support/knowledgecenter/SSNW2F_5.2.1/com.ibm.p8.security.doc/p8psh007.htm

One way to automate this process would be to use an event action in an asynchronous subscription to set the SecurityFolder property. 

 

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(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);
      }

}

 

For more information on subscriptions see:  https://www.ibm.com/support/knowledgecenter/SSNW2F_5.2.1/com.ibm.p8.ce.dev.ce.doc/subscription_concepts.htm

 

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSNVNV","label":"FileNet Content Manager"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

UID

ibm11280578