Properties of Objects available in script contexts

Properties of Objects available in script contexts

Norsk

The operations and methods available depends on the type of objects you are operating with. Use this overview as a simplified encyclopedia while scripting in Compose.

Type of Object available in scripts based on validation

Validation

Type of Object available in scripts

String Based Validation

 

String

java.lang.String

Integer

java.math.BigInteger

Decimal

java.math.BigDecimal

Date

DateObj

File Based Validation

 

Binary

BinaryFileObj

PDF

PDFFileObj

Text

TextFileObj

XML

XMLFileObj

Properties available for DateObj

Property

Description

year

Year as integer

month

Month as integer (1-12)

day

Day a integer (1-31)

asString

String representation. Takes the form of "Y-MM-DD". e.g: 2013-04-01

format("Y/MM/DD")

formats the date according to the passed in format

Properties available for an Object representing a File

Property

Description

filename

Returns the file name as a String.

contentType

Returns the content type as a String.

content.size()

Returns the size of the content.

content.bytes()

Returns a byte[] related to the file content.

Additional properties depend on the type of Object which could be either a TextFileObj, XMLFileObj, PDFFileObj or BinaryFileObj.

Properties available for TextFileObj

Property

Description

encoding

Returns the encoding as a String.

textReader

Returns a java.io.Reader instance for the text file content.

getTextReader("ISO-8859-1")

Returns a java.io.Reader instance in the specified encoding for the text file content.

Properties available for XMLFileObj

Property

Description

encoding

Returns the encoding as a String.

textReader

Returns a ‘java.io.Reader’ instance for the text file content.

getTextReader("ISO-8859-1")

Returns a ‘java.io.Reader’ instance in the specified encoding for the text file content.

XMLElements

Returns the ‘org.w3c.dom.Document’ instance representing the XML file (This essentially exposes the XML file via the DOM API)

XMLStreamReader

Returns an instance of ‘javax.xml.stream.XMLStreamReader’ implementation representing the XML file (This essentially exposes the XML file via the StAX API).

Properties available for PdfFileObj

Property

Description

pdfVersion

Returns the pdf version as a String.

Properties available for BinaryFileObj

No additional properties available on top of what is available for FileObj.

Question object

Property

Description

question

Returns an Object having details about the question.

Other available properties depend on the type of the related question answer. A given question answer object could be an instance of either ValueInputQuestion, SingleSelectQuestion, MultiSelectQuestion or FileQuestion.

ValueInputQuestion

Property

Description

answer

Answer value. Depends on the data type of question. May be an instance of BigDecimal, BigInteger, String or an Object representing date. Note that answer value will be null, from the scripts point of view, if empty or if submitted value does not conform to the data type.

SingleSelectQuestion

Property

Description

answer

Returns an Object representing the selected option details. This could be null if no option has been selected.

It is recommended to use syntax like Q21.answer?.value in the context of select questions. ? is a Groovy null safe operator. Use of it prevents null pointers from happening when answer is null (i.e: when no answer has been selected)

MultiSelectQuestion

Property

Description

answers

List of select option objects related to selected options. List will be empty if no options are selected.

FileQuestion

Property

Description

answer

Answer value. Note that answer value will be null, from the scripts point of view, if empty or if a value that does not conform to the data type of the question.

Additional properties for select option

Property

Description

value

Answer value that may be an instance of BigDecimal, BigInteger, String or an Object representing date.

label.text

Gets the label value of the option localized according to the respondent users’ language. Returned object will be a String.

label.getText()

Gets the label value of the option localized according to the respondent users’ language. Returned object will be a String.

label.getText("eng")

Gets the label value of the option localized according to the passed in language code. Returned object will be a String.

Additional properties for questions

Property

Description

id

Id of question, e.g. "Q12".

label.text

This gives the localized question label for the language used by the respondent.

label.getText()

Same result as invoking "Q12.question.text".

label.getText("eng")

This gives the localized question label for the language code passed in. If null is passed default value will be returned.

Properties available for a form object

Property

Description

id

Gives the id of the Form as a String. i.e.: the repository item id

version

Gives the version of the Form as a String.

Available properties for formatted text

Property

Description

plainText

Returns the text without markup information. e.g.: Q13.question.text.plainText

html4

Returns the text with html markup information. e.g.: Q13.question.text.html4

markup

Return the original formatted text with markup information. e.g.: Q13.question.text.markup

xml

Return the formatted text without any markup information which can be used in a xml. i.e: xml sensitive characters would be escaped. e.g.: Q13.question.text.xml

Properties available for question group answer object

Property

Description

groupId

Id of question group, e.g. QG1.

questionAnswers

Returns a Map of questions directly under the group. Key is the question id. Value is an object representing question answer information.

questionGroupAnswers

Returns a Map of question groups at root level. Key is the question group id. Value is a list of Objects representing question group answer information.

Q42

Returns an object containing details related to the question with ID Q42 under this question group.

QG2

Returns a list of objects containing details related to the question group with id QG2 under this question group.

This object effectively forms a tree structure.

Properties available for a form answer based input variable.

Property

Description

questionAnswers

Returns a Map of questions at root level. Key is the question ID, value is an Object representing question answer information.

questionGroupAnswers

Returns a Map of question groups at root level. Key is the question group id. Value is a list of Objects representing question group answer information.

form

Returns an object containing information about the form.

Q21

Returns the 1st instance of Object containing question answer information related to question with ID Q21.

QG1

Returns a list of Objects containing information about question group answers related to QG1.

Properties available for Util Objects

Method

Description

Util.escapeXml(value)

Escapes characters so that value can be used safely in an XML-tag.

Util.escapeHtml4(value)

Escapes characters so that value can be used safely in an HTML4 document.

Util.currentTime()

Gets current system time as a String in standard format: "yyyy-MM-dd HH:mm:ss.SSS". Output could be e.g. "2012-11-14 15:47:54.365"

Properties available for Object representing user agent information

Method

Description

items

List of ‘items’ representing user agent information. A given item could be either a Product or a Comment (see tables below).

text

Returns the original user agent string trimmed

untrimmedText

Returns the original user agent string

Properties available for Product

Method

Description

name

String value giving the name of the product

version

String value giving the version of the product

text

Trimmed text value represent the core string value from the original user agent string

untrimmedText

Untrimmed text value represent the core string value from the original user agent string

Properties available for Comment

Method

Description

details

List of String values representing the comment

text

Trimmed text value represent the core string value from the original user agent string

untrimmedText

Untrimmed text value represent the core string value from the original user agent string.