You are here: Business Rules > Business Libraries

Business Libraries

Business Libraries are a set of functions that can be reused in multiple business rules or other libraries. Libraries cannot be called independently and must be referenced from other actions or conditions.

Like actions and conditions, business libraries are objects that live in System Setup.

In business libraries, any number of JavaScript business rules can be drawn from to define library functions. It is not possible to bind STEP objects when working with libraries, but they can be passed in as arguments.

For business rules where library functionality is to be used, you must declare a dependency to the libraries. This is done so on the Dependencies tab.

For example: To check if a product is below another product , the following library function is used:

// Checks whether a Product is below another Product
function isProductBelow(prod, checkProdID) {
if(!prod instanceof com.stibo.core.domain.Product) throw "Function only works with Products";
if(checkProdID == "Product hierarchy root") return true;
if(prod.getID() == "Product hierarchy root") throw "The top level Product is never below another Product.";
var currentParentId;
var currentProd = prod;
while(true) {
currentParentId = currentProd.getParent().getID();
if(currentParentId == "Product hierarchy root") return false;
else if (currentParentId == checkProdID) return true;
else currentProd = currentProd.getParent();
}
}
Condition using function (Library alias = “lib”, Current Object bound to variable "obj")
return lib.isProductBelow(obj, "ID of STEP Product");

2017, Stibo Systems