Javascript Library¶
The following javascript functions are available for use with the Javascript block.
oi¶
createInstance(model,instanceName)¶
Create a new model instance of a model and give it a name.
Returns¶
MetadataObject
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
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 |
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. |
isInstance()¶
Returns true if the current action sequence is executing in an model instance (as opposed to a model)
Returns¶
bool
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
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.