# Script-handler Handler

It ca be used to persist the business objects using BSH scripts. Supports the following attributes:

<div id="bkmrk-attribute-usage-if-e"><table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" role="grid"><thead class="tableFloatingHeaderOriginal"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" aria-label="Attribute: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col" tabindex="0"><div>**Attribute**</div></th><th aria-disabled="false" aria-label="Usage: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col" tabindex="0"><div>**Usage**</div></th></tr></thead><tbody aria-live="polite" aria-relevant="all"><tr role="row"><td class="confluenceTd">if

</td><td class="confluenceTd">EL expression that must be evaluated to true prior to handler action

</td></tr><tr role="row"><td class="confluenceTd">unless

</td><td class="confluenceTd"> EL expression that must be evaluated to false prior to handler action</td></tr></tbody></table>

</div><span class="notranslate">Inside the handler, you can use the insert-script, delete-script and update-script tags.</span> <span class="notranslate">Each contains the BSH script that the engine will execute to perform inserts, deletes or updates.</span> <span class="notranslate">Within the BSH script you can refer to the same EL expressions predefined variables:</span>

<div id="bkmrk-variable-value-self-"><table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" role="grid"><thead class="tableFloatingHeaderOriginal"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" aria-label="Variable: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col" tabindex="0"><div><div>**Variable**</div></div></th><th aria-disabled="false" aria-label="Value: No sort applied, activate to apply an ascending sort" aria-sort="none" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col" tabindex="0"><div><div>**Value**</div></div></th></tr></thead><tbody aria-live="polite" aria-relevant="all"><tr role="row"><td class="confluenceTd">self</td><td class="confluenceTd">Current DataNode</td></tr><tr role="row"><td class="confluenceTd">instance</td><td class="confluenceTd">Business object wrapped into current DataNode</td></tr><tr role="row"><td class="confluenceTd">parent</td><td class="confluenceTd">Parent DataNode</td></tr><tr role="row"><td class="confluenceTd">parent.instance</td><td class="confluenceTd">Business object wrapped into parent DataNode</td></tr><tr role="row"><td class="confluenceTd">datasource</td><td class="confluenceTd">DataSoruce the current DataNode belongs to</td></tr></tbody></table>

</div><span class="notranslate">The following example shows how to save objects in file Country:</span>

```XML
<datanode name="country">
    <script-handler >
        <insert-script>
            import java.io.*;
            f = new FileOutputStream ("country."+instance.abbreviation);
            oos = new ObjectOutputStream (f);
            oos.writeObject (instance);
            oos.close ();
            f.close ();
        </insert-script>
        <update-script>
            import java.io.*;
            f = new FileOutputStream ("country."+instance.abbreviation);
            oos = new ObjectOutputStream (f);
            oos.writeObject (instance);
            oos.close ();
            f.close ();
        </update-script>
        <insert-script>
            import java.io.*;
            f = new File ("country."+instance.abbreviation);
            f.delete ();
        </insert-script>
    </script-handler>
        ...
</datanode>
```