A Business Library is a set of JavaScript functions that can be reused in multiple business rules. The following should be reviewed when considering the use of a business library:
As an example, the following library function could be used to check if a product is below another product:
// 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");
2020, Stibo Systems – Confidential