UCSD Custom WF Tasks: Storing Reusable Functions in a Script Module

Version 2

    As custom workflow tasks become more complex and lengthy, it becomes desirable to store reusable functions within a script module library rather than have them clog up the workflow tasks themselves. The following description shows how this is achieved with UCS Director.

     

    Taking the following CloupiaScript as an example, the catalogNameFromID() function (Which will return the catalog name for a given catalog ID) will be stored in a Script Module library.

    Screen Shot 2015-04-15 at 08.58.25.png

     

    importPackage(com.cloupia.service.cIM.inframgr);

    //----------------------------------------------------------------------------------------

    //

    // Function Name: catalogNameFromID(catalogID)

    //

    //       Version: 1.0

    //

    //    Parameters: catalogID;           Catalog ID.

    //

    //       Returns: catalogName;

    //

    //      Requires: importPackage(com.cloupia.service.cIM.inframgr);

    //               

    //   Description: Returns the text name for a given catalog ID.

    //

    //----------------------------------------------------------------------------------------

    function catalogNameFromID(catalogID) {

        this.catID = catalogID;

     

        this.cat2 = VDCUtil.getVDCCatalogItem(this.catID);

     

        return this.cat2.getCatalogItemName()

    }

     

    logger.addInfo("Catalog Name: " +catalogNameFromID(18) );

     

     

    Policies -> Orchestration -> Script Module -> Add:

    Screen Shot 2015-04-15 at 08.51.51.png

     

    Enter a name for the new module and click Submit:

    Screen Shot 2015-04-15 at 08.52.41.png

     

    Double-click the new module and click Add to create a new library:

    Screen Shot 2015-04-15 at 08.53.32.png

     

    Give the new library a name (myFunctions in this example) and paste in the your function(s):

    Screen Shot 2015-04-15 at 08.54.12.png

    Click Submit:

    Screen Shot 2015-04-15 at 08.55.04.png

     

    The original custom task can now be modified as so:

     

    loadLibrary("myModule/myFunctions");


    logger.addInfo("Catalog Name: " +catalogNameFromID(18) );

     

    …which produces the following output:

    Screen Shot 2015-04-15 at 08.56.58.png