IBM Support

A Javascript example of changing a property value for document objects using a custom sweep in IBM FileNet Content Manager

Question & Answer


Question

A Javascript example of changing a property value for document objects using a custom sweep in IBM FileNet Content Manager

Answer

In the Administration Console for Content Engine (ACCE) you can create a custom sweep to update a property value for document objects. A custom sweep retrieves instances of a target class and processes them with a user implemented action handler. Like a system sweep, a custom sweep operates as a background task on the server and passes retrieved instances to an action handler for processing. In both cases, a filter condition can be applied to the sweep to narrow the scope of the retrieved instances. However, a system sweep performs an action that is built into the server, whereas a custom sweep performs an action that is added to the server by an administrator. There are three basic components you need to create a custom sweep.

    1. Create a Java™ or JavaScript sweep action handler. Here is an action handler that will update the Document Title property.

        importPackage(Packages.com.filenet.api.core);
        importPackage(Packages.com.filenet.api.constants);
        importPackage(Packages.com.filenet.api.exception);
        importPackage(Packages.com.filenet.api.sweep);
        importPackage(Packages.com.filenet.api.engine);

        // Implement for custom job and queue sweeps.
        function onSweep (sweepObject, sweepItems)
        {
        var hcc = HandlerCallContext.getInstance();
        hcc.traceDetail("Entering CustomSweepHandler.onSweep");
        hcc.traceDetail("sweepObject = " + sweepObject.getProperties().getIdValue(PropertyNames.ID) + "sweepItems.length = " + sweepItems.length);

        // Iterate the sweepItems and change the class.
        ii = 0;
        for (ii = 0; ii < sweepItems.length; ii++)
        {
        // At the top of your loop, always check to make sure
        // that the server is not shutting down.
        // If it is, clean up and return control to the server.
        if (hcc != null && hcc.isShuttingDown())
        {
        throw new EngineRuntimeException(ExceptionCode.E_BACKGROUND_TASK_TERMINATED, this.constructor.name + " is terminating prematurely because the server is shutting down");
        }
        var item = sweepItems[ii].getTarget();
        var msg = "sweepItems[" + ii + "]= " + item.getProperties().getIdValue("ID");
        hcc.traceDetail(msg);

        try
        {
        var CEObject = com.filenet.api.core.Document (item);
        CEObject.getProperties().putValue("DocumentTitle","This is your new document title");
        CEObject.save(com.filenet.api.constants.RefreshMode.NO_REFRESH);

        // Set outcome to PROCESSED if item processed successfully.
        sweepItems[ii].setOutcome(SweepItemOutcome.PROCESSED,
        "item processed by " + this.constructor.name);
        }
        // Set failure status on objects that fail to process.
        catch (ioe)
        {
        sweepItems[ii].setOutcome(SweepItemOutcome.FAILED, "CustomSweepHandler: " +
        ioe.rhinoException.getMessage());
        }
        }
        hcc.traceDetail("Exiting CustomSweepHandler.onSweep");
        }

        /*
        * Called automatically when the handler is invoked by a custom sweep job
        * or sweep policy. Specify properties required by the handler, if any.
        * If you return an empty array, then all properties are fetched.
        */
        function getRequiredProperties()
        {
        var pnames = ['Id'];
        return pnames.toString();
        }

        /* Implement for custom sweep policies.
        * This method is not implemented because this is an example of a custom sweep job.
        */
        function onPolicySweep (sweepObject, policyObject, sweepItems)
        {}


    2. Create a custom sweep action:
    • In ACCE, start the New Sweep Action wizard:
    • In the domain navigation pane, click the object store.
    • In the object store navigation pane, right-click the Sweep Management > Sweep Actions folder and click New Sweep Action.
    • Complete the wizard.


    3. create a custom job sweep:
    • In ACCE, Start the New Custom Job wizard:
    • In the domain navigation pane, select the object store.
    • In the object store navigation pane, select the Sweep Management > Job Sweeps > Custom Jobs folder.
    • Click New.
    • Optional: Select the Enabled property to enable the sweep to run.
    • Note: Some sweep properties cannot be set in the wizard; they can only be set in the sweep object after it is created. Time slots and FilteredQueryTimeout are two such properties. If you need to change default values of properties that are not available in the wizard, disable the sweep in the wizard. You can enable the sweep later, after you change default property values in the sweep object.
    • Complete the wizard.

[{"Product":{"code":"SSNVNV","label":"FileNet Content Manager"},"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","Edition":"All Editions","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
17 June 2018

UID

swg21984947