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.
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:
Enter a name for the new module and click Submit:
Double-click the new module and click Add to create a new library:
Give the new library a name (myFunctions in this example) and paste in the your function(s):
Click Submit:
The original custom task can now be modified as so:
loadLibrary("myModule/myFunctions");
logger.addInfo("Catalog Name: " +catalogNameFromID(18) );
…which produces the following output: