Skip to main content

JavaScript API


Repository Document

Root object: rd
Example: rd.getCreatedDate()

Add a single generic field to a document:
addSingleField(String, Object)

Add multiple values to a single field:
addArrayField(String, Object[])

Add a single Date to a field:
addSingleDateField(String, Date)

Add multiple date values to a single field:
addDateArrayField(String, Date[])

Return the created datetime of the source document as a Date:
getCreatedDate()

Return the length of the binary (first binary) as a long:
getFileLength()

Return the length of the first binary, or the originalFileLength if there are no binaries:
getDocumentLength()

The original file length is set with the first file length value applied to the document, and will not change even if the binaries change:
getOriginalFileLength()

Set the original file length field for the document:
setOriginalFileLength(long)

Return the name of the file as a String:
getFileName()

Return the last access datetime of the document as a Date:
getLastAccessedDate()

Return the hash value of the document's content as a String. In the case of multiple binaries, only the hash of the first will be returned:
getHashValue()

Return the modified date of the documents as a Date:
getModifiedDate()

Return the logical path (folder path) of the document from the source system as a String. If the document is a folder, this will be the parent folder, with the folder name's being the file name:
getPath()

Set the filename of the document on the first binary:
setFileName(String)

Set the path of the document. This can be used to modify the output location:
setPath(String)

Set the modified date of the document:
setModifiedDate(Date)

Return the mimetype as a 'String'. The int index is for files with multiple binaries, in most cases this will be 0. The returned format is type/subtype:
getMimeType(int index)

Set the mimetype of the first binary. If not binary is available, a default binary will be added with the set mimetype:
setMimeType(String)
Example: doc.setMimeType('application/octet-stream');


Binaries

Example: var binaries = rd.getBinaries()

Produces a list of Simflofy Binary objects. The list will be empty if there is no binary

Simflofy Binary Methods

getFileName()

Returns the file name of the binary. Default value is default_document_name.doc

setFileName(String)

Sets the file name on the binary

getLength()

Returns the length of the binary. Will return -1 if the binary has no content.

setLength(long)

Sets the length of the binary

getMimeType()

Returns the mimetype of the binary. Default is application/octet-stream

setMimeType(String)

Sets the mimetype of the binary

getInputStream()

Returns the content of the document as an InputStream object. Not recommended for use.

setInputStream(InputStream)

Sets the content on the binary.

getHashValue()

Return the hash value for the binary. Default is empty.

setHashValue(String)

Sets the hash value for the binary.


Document Fields

Obtained document fields with rd.getDocumentField(String)
Example: var field = rd.getDocumentField("title")

Produces a DocumentField object with the following methods. Returns null if the field is not present.

DocumentField Methods

Return the name of the field as a String:
getFieldName()

Return the field value: getFieldValue()
Example: rd.getDocumentField('myfield').getFieldValue();

Check if the value of the field is an array:
isFieldValueArray()

Return the field value as an array of Objects (even single values):
getFieldValueAsArray()

Return the data type of the field:
getFieldType()

Return a JSON Object containing the keys "name","type","value":
toJSONObject()

Get a case-insensitive version of getDocumentField():
getDocumentFieldWithLowerCase(String)

Return a FieldStringValueHolder object with some utility methods for checking field content:
getFieldAsStringHolder(String)

Check if the field is empty and return a boolean value:
isEmpty()

Check if the field has multiple values (multi-valued fields). This returns a boolean value:
isArray()

Return the values as a comma delimited list:
getSingleStringValue()

Return the value as a String array:
getArrayValue()


Versions

Example: var versionInfo = rd.getVersionInfo()

Produces a VersionInfoBean object. Null if none is present. If retrieving versions from the source repository, the task will process them in order.

VersionInfoBean Methods

getTotalVersions() - Returns an int value

getLabel()

getFileName()

getLastModified() - returns a long in timestamp format

getFileLength() - returns a long in bytes

getPath()

isLatest() - returns a boolean value

isMajor() - returns a boolean value

getObjectId

Return a map of field names and document field objects. See the sample code for more information on using the map:
getFieldsMap()


Log Accessor

Root object: log
Example: log.debug("This is debug logging");

Access to standard output. In order to see logging in the simflofy-admin.log you will need to add the following appender to the log4j.properties (requires restart) or in the Admin > Logging section of simflofy admin:

log4j.logger.com.simflofy.tasks.processors.JavaScriptExecutorTask + the desired log level.

Example:
log4j.logger.com.simflofy.tasks.processors.JavaScriptExecutorTask=DEBUG

Each method will log to the appropriate level:

info()

debug()

trace()

error()


Job ID

Current job ID:
Root object jobId


Job Run ID

Current job run ID:
Root object jobRunId


Printing

If you wish to print to the console (the equivalent of System.out.println), use the command print();