Skip to main content

Beanshell vs Javascript

Introduction

Soffid 4 configures the smart engine with the JavaScript engine by default.

Previously, the default engine was Beanshell, and many scripts will need to be adapted.

This page lists these differences.

Table of differences

Topic Beanshell Javascript
variable s = "text";

// The use of var should be mandatory,

//but it almost always works without using it.

var s = "text";

 

or

 

s = "text";

function public void doSomething(String system) {
  ...
}
doSomething("APP_USERS");
function doSomething(system) {
  ...
}
doSomething("APP_USERS");
for

for (user : listOfUsers) {

  ...

}

for (var i=0; i<listOgUsers.size(); i++) {
  ...
equals

user == null

user === null
equals

userName.equals("myName")

userName === "myName"
java class

es.caib.seycon.ng.comu.AccountType

Java.type("es.caib.seycon.ng.comu.AccountType")

 

// We can also generate objects without Java.type

query = new com.soffid.zkdb.api.Query();

 

or

 

Query = Java.type("com.soffid.zkdb.api.Query");

query = new Query();

Search in Soffid 4


List users simple

q = new com.soffid.zkdb.api.Query();
pr = serviceLocator.getUserService().findUsers(q);
lu = pr.getResources();
for (i=0; i<lu.size(); i++) {
  u = lu.get(i);
  out.println(u.userName);
}

List usera with pagination

us = serviceLocator.getUserService();
q = new com.soffid.zkdb.api.Query();
q.startIndex = 0;
q.pageSize = 2;
do {
  out.println("Searching...");
  pr = us.findUsers(q);
  lu = pr.getResources();
  for (i=0; i<lu.size(); i++) {
    u = lu.get(i);
    out.println("   "+u.userName);
  }
  q.startIndex = q.startIndex+pr.itemsPerPage;
} while (q.startIndex<pr.totalResults);