Skip to main content

Script Types

The following scripts serve to automate form filling and verification in docuRob® eForms :

  • Form preparation scripts – run in the form controller before displaying the form to the user, it allows form initialization to be performed before the user begins filling in or viewing the form.
  • Form data verification scripts – run in the form controller after the user selects the form data saving operation, it enables comprehensive verification of data entered by the user.

Script Editor

The script editor is a component of the form editor that is opened using the button ****available on the form window toolbar. The script editor allows you to define form preparation and verification scripts.

Script Editor Window

The script editor window consists of a top menu, tabs that switch the script editing area (select the type of script to edit), a script editing area, and a bar containing the line number.

The top menu consists of two submenus: File and Edit ( Figure 3 ). The File submenu contains the basic Save and Close operations . The Edit submenu contains the basic operations available in standard text editors ( Undo , Copy , Cut , Paste , Select All , Find , Replace , Go to Row , Refresh ). It also contains the operation of pasting a template script ( Paste Template Script ) by means of which a template script created on the basis of the current form definition will be pasted in the place where the cursor is currently located. The template script contains examples of the following operations:

  • getting the value of each form field for which a binding to a type attribute or field name has been defined,
  • downloading all areas defined in the form,
  • modifying the attributes of one of the areas,
  • example of reporting error messages for a form.

All menu items can be invoked using keyboard shortcuts.

The middle part of the window is occupied by the script editing area where the form designer can define the source code of the form script. To save modifications to the source code of the script, select Save from the File menu.

Figure 3. Menu of functions supporting editing of form scripts

Predefined script elements

A form script is a Java™ program in which the form designer can declare classes, methods, and the actual script code. In order to retrieve data contained in the form, the script designer can use predefined objects that allow for easy retrieval of any information about the form and data contained in the form, and it is also possible to modify the form state.

The meaning of predefined objects in form script is as follows:

  • cells – a map ( java.util.Map ) of objects representing form fields, for duplicated fields it is an array of objects whose type depends on the field type (e.g. for a date field in a duplicated row it is pl.rodan.eforms.cell.DateCell [] ), for regular fields it is an object whose type depends on the field type (e.g. for an integer field it is an object of pl.rodan.eforms.cell.IntegerCell ).
  • form – an object representing a form (of type pl.rodan.eforms.Form ).
  • attributes – a map ( java.util.Map ) of attributes passed to the form in the application in which the form is embedded (the names of the attributes passed to the form depend on the application in which the Product is used).
  • logger – an object that allows you to report error messages for the form (using the addError (String) method ), error messages will be presented to the user filling the form.
  • TmHelper – an object allowing access to the TopicMap data of the current form

The API documentation of objects available in scripts is available in JavaDoc ™ format on the forms repository application pages. To obtain the documentation address, add /docs/api/index.html to the forms repository address (available in the Form Editor configuration menu) . For example, for the forms repository address Repository_address , the address documentation is as follows: Documentation.

Script Examples

Hiding Form Areas

The form has pre-defined areas named "list" and "dates". The system can pass an attribute named “frontoffice” to the form, if this attribute is passed with the value true the area named list " should be hidden and the area named dates should become read-only.

Form preparation script

String frontoffice = (String)attributes.get("frontoffice");
if ("true".equals(frontoffice)) {
    FormArea lista = form.getFormAreas().getFormArea("lista");
    lista.setHidden(true);
    FormArea daty = form.getFormAreas().getFormArea("daty");
    daty.setReadOnly(true);
}

Filling the field with the current date

The form defines a date type field called "submission date". It is necessary to ensure that this field is automatically filled with the current date when it is not filled in.

Form preparation script

DateCell dateCell = ( DateCell ) cells.get (" submission date ");
if ( dateCell.getTypedValue () == null) {
dateCell.setDate (new java.util.Date ());
}

Form field compliance check

The following date type fields have been defined on the form, associated with type attributes named Schedule.StartDate and Schedule.EndDate . Additionally, numerical type fields have been defined, named "net amount", "vat" and "gross amount". It should be ensured that the start date is earlier than the end date, and the sum of the net amount and vat is equal to the gross amount. If these conditions are not met, an error message should be sent to the user.

Form Data Validation Script

Date startDate = (Date) cells.get (" Schedule.StartDate ")
.getTypedValue () ;
Date end date = (Date) cells.get (" Schedule.EndDate ")
.getTypedValue () ;
if ( dateStart.getTime () > dataStart.getTime ()) {
logger.addError ("Start date must be earlier than end date");
}
Double amountNet = (Double) cells.get (" amount net ") .getTypedValue ();
Double vat = (Double) cells.get ("vat"). getTypedValue ();
Double amountGross = (Double) cells.get (" amount gross "). getTypedValue ();

if ( Net amount.doubleValue () + vat.doubleValue () != Gross amount.doubleValue ()) {
logger.addError ("The sum of net and vat amounts is not equal to gross amount");
}

Downloading parameters passed to the form

Form Data Verification Script/Form Preparation Script

java.util.Map extraParamsForForm = ( java.util.Map ) attributes.get (" extraParamsForForm ");
if ( extraParamsForForm != null) {
java.lang.String newCellValue = ( java.lang.String ) extraParamsForForm.get (" case_no ");
}

Getting form field values

Retrieving the value of a form cell. The template script that can be generated in the script definition window contains examples of retrieving the value of all cell types present in a given form.

Form Data Verification Script/Form Preparation Script

StringCell nameCell = ( StringCell ) cells.get (" CaseName "); DictionaryCell nameCell_zw = ( DictionaryCell ) cells.get (" return_toMK_FR "); BooleanCell boolCellE2 = ( BooleanCell ) cells.get (" electronic_EM "); extraParamsForForm.get (" case_no "); ...

Getting and setting the visibility of the Form Area

Form Data Verification Script/Form Preparation Script

FormArea pom = form.getFormAreas (). getFormArea (" Help ");
pom.setHidden (true);

Setting dictionary field values

Setting the dictionary field with a specific value taken from the dictionary ( Topic Maps )

Form Data Verification Script/Form Preparation Script

DictionaryCell dictCell = (DictionaryCell)cells.get("application_for_sale.RETURN_TYPE_WITH_APPROVAL_INTRODUCTION");
en.rodan.topicmaps.TMTopic item = tmHelper. findTopicByIndicator ("http://www.rodan.pl/psi/obsl.-dow.-ksiegowych-zapowiedz-wstepne,-rodzaj-zwrotu/przezanie-do-zatwierczenia-ostateczny");
dictCell.setSelectedDictionaryItemId ( item.getId ());

Deleting the logical value of form fields

Deleting the value of a logical field and a multi-line text with a given name

Form Data Verification Script/Form Preparation Script

((BooleanCell)sheet.getCellByName("confirmProcedure")).setBooleanValue(Boolean.FALSE); ((MultilineTextCell)sheet.getCellByName("procedure notes")).setStringValue("");

Filling the row with data

Takes the line at index 69 and inserts strings ( notesString , confirmationString , personString ) into its appropriate fields ( person, confirmationString , commentsString ).

Form Data Verification Script/Form Preparation Script

String uwagiString = "Chciałbym zauważyć że..."
String potwierdzenieString = "Chciałbym potwierdzić że..."
String osobaString = "Freddy Mercury"
int rowIndex = 69;
HorizontalCellLine row = sheet.getRow(rowIndex);
Iterator it = row.getCells().iterator();
while (it.hasNext()) {
Cell cell = (Cell)it.next();
String cellName = cell.getCellName();
if ("osoba".equals(cellName) ) {
((StringCell)cell).setStringValue(osoba);
} else if ("potwierdzenie".equals(cellName) ) {
((StringCell)cell).setStringValue(potwierdzenie);
} if ("uwagi".equals(cellName) ) {
((StringCell)cell).setStringValue(uwagi);
}
}

Setting up a new dictionary

The dictionary defined using PSI is set in the dictionary field named NAME.

Form Data Verification Script/Form Preparation Script

DictionaryCell dc = ( DictionaryCell ) cells.get ("NAME"); dc.setDictionaryId("http://www.rodan.pl/psi/kategoria-parametrow/dane-adresowe");

Cutting out entries from the dictionary

Limit the number of entries in the dictionary to only those with PSI specified in neededPSIList .

Form Data Verification Script/Form Preparation Script

try {
// zamiana psi na id liczbowe
HashMap neededKeys = new HashMap();
for (int i=0; i<neededPSIList.size(); i++ ) {
String psi = (String)neededPSIList.get(i);
String key = getTopicIdFromPSI(psi);
neededKeys.put(key, key);
}
FormDictionariesList dictionaries = form.getFormDictionaries();
if (dictionaries != null) {
// Mapa pozycji słownikowych do odania do słownika
HashMap items = new HashMap();
// pobranie oryginalnego slownika
FormDictionary dictionary = dictionaries.getFormDictionary(dictionaryId);
// przepisanie tylko pozadanych pozycji
Map map = dictionary.getValues();
java.util.Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
if (neededKeys.containsKey(key)) {
items.put(key, map.get(key));
}
}
dictionaries.removeItem(dictionary);
dictionary = new pl.rodan.eforms.impl.DefaultFormDictionary(dictionaryId, items);
dictionaries.registerFormDictionary(dictionary);
}
} catch (Exception e) {
logger.addError("ERROR:"+e.getMessage());
}
DictionaryCell dc = (DictionaryCell)cells.get("d1");
if (dc != null) {
String dictionaryId = dc.getDictionaryId();
ArrayList neededPSIList = new ArrayList();
neededPSIList.add("PSI");
reduceDict(dictionaryId, neededPSIList);
}

Conversion PSI of TMTopic object

Converting the PSI of a TMTopic object to its id.

Form Data Verification Script/Form Preparation Script

String getTopicIdFromPSI(String psi) {
pl.rodan.topicmaps.TMTopicMap tm = pl.rodan.topicmaps.TMManagerFactory.getManager().getDefaultProvider().getDefaultTopicMap();
pl.rodan.topicmaps.TMTopic item = tm.findTopicByIndicator(psi);
if (item == null) {
logger.addError("Nie znaleziono pozycji:"+psi);
return null;
}
return item.getId();
}