Javascript Library

The following javascript functions are available for use with the Javascript block.

oi

model(name)

Creates a new model reference for the model with the given name

Returns

model

createInstance(model,instanceName)

Create a new model instance of a model and give it a name.

Returns

MetadataObject

setOutput(key, value)

Sets an output for an action.

See also

Output

instance(key)

Obtain a reference to an model instance with the given key.

Returns

model

currentModel()

Obtain a reference to the current executing model.

Returns

model

currentInstance()

Obtain a reference to the current executing model instance.

Returns

model

parseDateTime(dt)

Parse a textual representation of a datetime.

Returns

timestamp

generateExcelSheet(columns, items)

Generate an excel sheet in xlsx format. Adds column headers and rows of data.

columns An array of column headers to add to the top.
items An array of objects to be populated as rows. Each object should have fields matching the items in the columns array

Example:

. code:

var columns = ['First Name','Last Name','Age'];
var data = [
    {'First Name':'Ricky','Last Name':'Ricardo','Age':36},
    {'First Name':'Ethel','Last Name':'Mertz','Age':34},
    {'First Name':'Fred','Last Name':'Mertz','Age':48}
];
var sheet = oi.generateExcelSheet(columns,data);

Returns

binary data object - the excel sheet as a binary data stream

currentUser()

Get attributes about the current logged-in user.

Returns

dictionary - a dictionary of attributes for the user. Available fields are:

  • UserKey - the iviva user key for the user
  • LoginID - the user’s iviva login id
  • Name - the user’s name
  • Email - the user’s email address
  • Phone - the user’s phone number
  • SiteKey - the user’s iviva site that he is configured for

now()

The current time in UTC format

Returns

timestamp

convertFromUtc(dt, tz)

Converts a timestamp from utc to a different timezone.

dt A timestamp to convert to a different timezone
tz The code of the timezone to convert to

Returns

timestamp converted to a different time zone

convertToUtc(now, tz)

Converts a timestamp to utc from a different timezone.

dt A timestamp to convert to UTC
tz The code of the timezone the timestamp was currently in.

Returns

timestamp converted to a different time zone

dateOnly(now)

Returns the date only with the time stripped out.

Returns

timestamp

escapeXml(name)

Escapes the character sequences suitable for embedding in xml.

Returns

string

isInstance()

Returns true if the current action sequence is executing in an model instance (as opposed to a model)

Returns

bool

executeService(service)

Execute an iviva service

Returns

result set

executeService(service,parameters)

Execute an iviva service, passing the given parameters

Returns

result set

guid()

Generate a globally unique identifier.

Returns

string

uploadData(name, data)

Upload the given data to the iviva storage, using name as a base name. The actual name used to store the data will be unique and randomly generated using name as part of it. This is to gaurantee no collisions with existing files.

The actual name used to store the data is returned. This name can be accessed via an http url of the form:

http://<ivivacloudurl>/content/OI/<filename>
name The base name for the file
data binary data object representing the data to be uploaded.

Returns

string - the actual file name that the data is saved as.

uploadDataWithExplicitName(name, data)

Same as uploadData(name, data) except the name specified is the exact name used to save the file. No extra unique postfix is added to the name.

Warning

This could potentially cause existing uploads to be overwritten if not used carefully. Do not use this function unless you have a very good reason for maintaining file names.

Returns

string

parseDataURI(uri)

Parse a data uri (specified as a string) into a binary data object

fromBase64(data)

Convert a base64 representation of data into a binary data object

binaryBlobFromText(txt)

Convert text into a binary data object

generateQRCode(data)

Encode the specified text data as a QR code image in png format.

model

isInstance()

Returns true if the object represents an model instance (as opposed to a model)

Returns

bool

deactivate()

Deactivate the current instance. Only works when the current object is an model instance

setAttribute(name, value)

Sets the attribute name with the value value in the current model instance Has no effect when run on a model.

getAttribute(name)

Gets the value of the specified attribute in the model instance. Has no effect when run on a model.

Returns

object

queryDataSource(datasource, arguments)

Query the datasource named datasource in the current object’s model’s linked UI. Pass arguments as parameters to the data source.

Returns

result set

executeAction(action, object arguments)

Execute an action named action on the current object, passing arguments as parameters.

Returns

dictionary