# Beanshell vs Javascript

## Description

<p class="callout info">Soffid 4 configures the smart engine with **Javascript** scripting language as the default. See [Smart engine settings](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/smart-engine-settings "Smart engine settings").</p>

<p class="callout warning">Previously, the default engine was Beanshell, and many scripts will need to be adapted.</p>

This page lists these differences.

## Related objects

- [Smart engine settings](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/smart-engine-settings "Smart engine settings") : where the engine is configured.
- Where we can use scripts: 
    - [Agents](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/agents "Agents") : properties, mappings and triggers
    - [Custom scripts](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/sample-scripts "Sample scripts") : all the scripts
    - [Account naming rules](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/account-naming-rules "Account naming rules") : script to validate and set name
    - [Role assignment rules](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/role-assignment-rules "Role assignment rules") : script to validate
    - [BPM editor](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/bpm-editor-addon-bpm "BPM editor (addon bpm)") : visualization, triggers, transitions
    - [Password policies](https://bookstack.soffid.com/books/soffid-4-reference-guide/page/password-policies "Password policies") : optional script

## Table of differences

<table border="1" id="bkmrk-topic-beanshell-java" style="border-collapse: collapse; width: 100%; height: 604.438px;"><colgroup><col style="width: 17.519%;"></col><col style="width: 35.4103%;"></col><col style="width: 47.0599%;"></col></colgroup><tbody><tr style="height: 29.875px;"><td style="height: 29.875px;">**Topic**</td><td style="height: 29.875px;">**Beanshell**</td><td style="height: 29.875px;">**Javascript**</td></tr><tr style="height: 130.578px;"><td style="height: 130.578px;">variable</td><td style="height: 130.578px;">s = "text";</td><td style="height: 130.578px;">// The use of var should be mandatory,

//but it almost always works without using it.

var s = "text";

or

s = "text";

</td></tr><tr style="height: 80.2344px;"><td style="height: 80.2344px;">function</td><td style="height: 80.2344px;">public void doSomething(String system) {  
 ...  
}  
doSomething("APP\_USERS");</td><td style="height: 80.2344px;">function doSomething(system) {  
 ...  
}  
doSomething("APP\_USERS");</td></tr><tr style="height: 63.4375px;"><td style="height: 63.4375px;">for</td><td style="height: 63.4375px;">for (user : listOfUsers) {

 ...

}

</td><td style="height: 63.4375px;">for (var i=0; i&lt;listOgUsers.size(); i++) {  
 ...  
} </td></tr><tr style="height: 29.875px;"><td style="height: 29.875px;">equals</td><td style="height: 29.875px;">user == null

</td><td style="height: 29.875px;">user === null</td></tr><tr style="height: 29.875px;"><td style="height: 29.875px;">equals</td><td style="height: 29.875px;">userName.equals("myName")

</td><td style="height: 29.875px;">userName === "myName"</td></tr><tr style="height: 164.172px;"><td style="height: 164.172px;">java class</td><td style="height: 164.172px;">es.caib.seycon.ng.comu.AccountType

</td><td style="height: 164.172px;">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();

</td></tr><tr style="height: 46.5938px;"><td style="height: 46.5938px;">catch / printStackTrace</td><td style="height: 46.5938px;">} catch(Exception e) {  
 e.printStackTrace(out);

}

</td><td style="height: 46.5938px;">} catch(e) {  
 out.println(e.message);

}

</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">  
</td><td style="height: 29.7969px;">e.printStackTrace(out)

</td><td style="height: 29.7969px;">out.println(e.message) + out.println(e.stack)

</td></tr></tbody></table>

## Search in Soffid 4

<p class="callout warning">In Soffid 4 the findObjectByJsonQuery method no longers exits, it has been replaced by findObjects with or without pagination.</p>

List users

```
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 users 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);
```