<< Click to Display Table of Contents >>
Scripts |
Scripts in Elipse Mobile are written in JavaScript. The available global parameters for access via scripts in a Form are described on the next table.
Parameters of a script on a Form
Parameter |
Description |
---|---|
state |
Form status. Possible values for this parameter are 0: Pending, 1: Attributed, 2: Finished, or 3: Approved |
assignedUser |
Name of a user attributed to this Form |
user |
Name of the user responsible for the last change on this Form |
timestamp |
Date and time of the last update on this Form |
fields |
Form fields |
To access the parameters described previously, use the format described next.
WriteTag("demo:TagInternal1",
form.assignedUser,
function(er) {
});
Fields on a Form, in the fields parameter, contain an id property, which is the field's internal identification, the notes property, which is used when fields have additional notes, the value property, which is the field's value, and the timestamp property, which is the field's date and time of the last update. Access to properties of a field must be performed according to the next example.
WriteTag("demo:TagInternal1",
form.fields.campo1.value,
function(er) {
});
When an answer is created on a Form, an OnChange event is triggered in the server. This event can be used to validate that Form, to copy data to another system, or to send an e-mail notifying changes to that Form, according to the next example.
function OnChange(form) {
//If the state parameter is equal to 2,
//Field's value is written to TagInternal1
if (form.state == 2) {
WriteTag("demo:TagInternal1",
form.fields.field1.value,
function(er) {}
);
}
}
To create a script for scheduling a Form creation on a specific day, for example, follow these procedures in a Demo-type Connection.
1.Select the Events tab and click Add .
2.Select the Script item.
3.Type a name for this event.
4.In the Condition option, type the next expression.
(new Date(ValueOf("demo:_now"))).getDay() == 5
5.The previous expression creates a new JavaScript Date object from the _now Tag and compares it to the value 5 (five, Friday).
NOTE |
For more information about the Date object in JavaScript, please check its documentation on Mozilla Developer Network (MDN). |
6.In the Script option, type the next source code.
SendMail("user",
"Form filling",
"Message",
function(er) {
});
7.This script is executed when the event enters a true condition, that is, when the weekday is equal to Friday. On all other days this script is not triggered.