CA Application Lifecycle Conductor

Expand all | Collapse all

Reusable Functions for Rule Scripts

  • 1.  Reusable Functions for Rule Scripts

    Posted 02-02-2017 08:22 AM

    Is there a way to define reusable functions that can be invoked by multiple rule objects?

    I find myself repeatedly copying and pasting common code into pretty much all my rule scripts see below example.

    It would be nice to have a shared facility to define these common functions and then be able to include or refer to them as needed.

     

    For example:

    /**
     * Log an info message
     * @param methodCtx - the "method" where the exception was caught
     * @param infoMsg -the info message
     */
    function logInfo(methodCtx, infoMsg){
     logError("", methodCtx, infoMsg);
    }

    /**
     * Log an exception
     * @param thrown - the exception
     * @param methodCtx -the "method" where the exception was caught
     * @param errMsg - error message
     */
    function logError(thrown, methodCtx, errMsg){
     try {
      VegasClient.createLogEntry(RULE_DESCR, methodCtx, errMsg, thrown.toString(), securityContext.getLogonId());
        } catch (ignoredEx) {}
    }



  • 2.  Re: Reusable Functions for Rule Scripts

    Broadcom Employee
    Posted 02-16-2017 11:54 PM

    You can create utility functions in a Java plugin added as static methods in a JAR file placed in ALC_HOME/lib/plugins.  There is no way at this time to do it in JavaScript but something to consider for a future release.  Thanks!