Publication examples

Ths document gives various examples of business object publications. Most examples are using the server-side Rhino scripting language.


The Rhino-only code examples can easily be transposed to equivalent Java code. Some examples are provided both in Rhino and Java so as you can see the syntax differences.

Apart from the variable and methods declarations syntax, the main point of attention is regarding comparisons syntax for non raw types:

  • Rhino: a == b, Java: a.equals(b)
  • Rhino: a != b, Java: !a.equals(b)

Print template types

Publication templates can use 3 processing mechanism:

The 2 first examples below are using substitutions, the last examples are using custom methods.

vCard publication

If a business objects includes identity data it may be published as a vCard to be imported on contact management systems, e-mail clients, mobile devices, ...

An example of vCard publication (using a dedicated publication template) is provided on the standard User object:

PHOTO;ENCODING=BASE64:[EXPR:res = DocumentDB.toBase64(obj.getField("usr_image_id").getValue(), obj.getGrant());]

Note the usage of a DocumentDB API for inlining the user picture as a base 64 encoded string, the global [BEGIN] / [END] publication template statements allows to export multiple vCards at the same time (beware that this bulk import is not possible with every e-mail clients).

For instance the import of published data renders as follows in Microsoft Outlook®:

RSS publication

The simplest approach for publishing business object data as a RSS feed is to configure a publication template such as the one used by default for the WebNewsobject (publication template name is WebNewsAsRSS):

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">

If the RSS is to be public the object must be granted in read mode to the PUBLIC group, so as the publication template.

Single record (form or list item) publication

Custom method for text content

The example below is for a simple printable HTML content:

MyObject.myPublicationMethod = function(pt) {
    try {
        var t = this.getFieldValue("myTitleField");
        var out = HTMLTool.openSimplePage(t, null, null);
        out += HTMLTool.cssBlock("@media print { @page { size: portrait A4; margin: 0; }");
        out += "<h1>" + pt.getLabel() + ": " + t + "</h1>";
        out += "<p>" + this.getFieldValue("myHTMLContentField") + "</p>";
        out += HTMLTool.closePage();
        return out;
    } catch(e) {

For text contents the return type of method must be String

Custom method for binary content

The example below is for a simple PDF content using the iText® library and its wrapper tool (publication template MIME type must be set to PDF):


MyObject.myPublicationMethod = function(pt) {
    try {
        var out = new;
        var pdf =;
        pdf.add(new Phrase(this.getFieldValue("myTextContentField")));
        return out.toByteArray();
    } catch(e) {

The example below is for a simple Microsoft Excel® content using the Apache POI® library and its wrapper tool (publication template MIME type must be set to XLS):

MyObject.myPublicationMethod = function(pt) {
    try {
        var xls = new ExcelPOITool(); // or ExcelPOITool(true); as of version 4.0, the true argument means using XLSX format
        var s = xls.newSheet(this.getLabel());
        var r = xls.newRow(0);
        r.add(xls.newCell(0, this.getFieldValue("myLabelField")));
        r.add(xls.newCell(1, this.getField("myValueField").getDouble()));
        return xls.generateToByteArray();
    } catch(e) {

The example below is for a simple Microsoft Word® content using the Docx4j® library (publication template MIME type must be set to DOCX):


MyObject.myPublicationMethod = function(pt) {
    try {
        var pkg = WordprocessingMLPackage.createPackage();
        var doc = pkg.getMainDocumentPart();
        doc.addStyledParagraphOfText("Title", this.getDisplay());
        var res = new;;
        return res.toByteArray()
    } catch(e) {

For binary contents the return type of method must be byte[]

Multiple records (list) publication

For list publications you must handle the list of explictly selected records and the case where no record has been explicitly selected.


var rows = new ArrayList();
var ids = this.getSelectedIds();
if (!Tool.isEmpty(ids)) {
    for (int k = 0; k < ids.size(); k++) {
        if (select(ids.get(k)))
        } else {
            rows =;

Then you can process the rows variable