Write, Bureaucrats, Administrators
4,332
edits
mNo edit summary |
mNo edit summary |
||
Line 187: | Line 187: | ||
Using scripts, you can check the correctness of input data and deny saving of data that fail the test. For example, perhaps a field integer values are allowed only from 0 to 200. | Using scripts, you can check the correctness of input data and deny saving of data that fail the test. For example, perhaps a field integer values are allowed only from 0 to 200. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
var num = entry().field("Number"); // Get value of field Number | var num = entry().field("Number"); // Get value of field Number | ||
Line 203: | Line 204: | ||
Suppose there is a library containing daily mileage of daily walks or use of a car or bicycle. Suppose the library has a StartingMileage field and a Mileage field. When an entry is created, the field StartMileage must get data from the field Mileage in the previous entry. | Suppose there is a library containing daily mileage of daily walks or use of a car or bicycle. Suppose the library has a StartingMileage field and a Mileage field. When an entry is created, the field StartMileage must get data from the field Mileage in the previous entry. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
var entries = lib().entries(); // Get current library & array of its entries | var entries = lib().entries(); // Get current library & array of its entries | ||
Line 223: | Line 225: | ||
Suppose you need to identify the beginning of a new day in the DateTime field. (The script requires connection of the JavaScript library '''moment.js''' [http://momentjs.com/ moment.js].) | Suppose you need to identify the beginning of a new day in the DateTime field. (The script requires connection of the JavaScript library '''moment.js''' [http://momentjs.com/ moment.js].) | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
var m = moment().add(1,'d'); // Using the moment.js library function moment(), | var m = moment().add(1,'d'); // Using the moment.js library function moment(), | ||
Line 328: | Line 331: | ||
==== Writing & reading from a file ==== | ==== Writing & reading from a file ==== | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
f = file("/sdcard/myfile.txt"); // Open the myfile.txt file on the SD card. If the file does not exist, | f = file("/sdcard/myfile.txt"); // Open the myfile.txt file on the SD card. If the file does not exist, | ||
Line 343: | Line 347: | ||
The entry includes fields: id , title , date. | The entry includes fields: id , title , date. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
var xml = '<record id="' + entry().field("id") + '">' + // Format XML record from the entry field values | var xml = '<record id="' + entry().field("id") + '">' + // Format XML record from the entry field values | ||
Line 385: | Line 390: | ||
We will create a Trigger on Event '''Create an entry to Add''' and Phase '''After saving the entry'''. | We will create a Trigger on Event '''Create an entry to Add''' and Phase '''After saving the entry'''. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
result = http().get("http://api.fixer.io/latest?base=USD"); // Use http://fixer.io/ for | result = http().get("http://api.fixer.io/latest?base=USD"); // Use http://fixer.io/ for | ||
Line 400: | Line 406: | ||
In the following example of task creation, text will be taken from the Memento library entry. | In the following example of task creation, text will be taken from the Memento library entry. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
// Create a JSON command for Todoist task creation | // Create a JSON command for Todoist task creation | ||
Line 488: | Line 495: | ||
Suppose a library contains a field called Phone containing a phone number. | Suppose a library contains a field called Phone containing a phone number. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
i = intent("android.intent.action.DIAL"); // Create information exchange object Intent | i = intent("android.intent.action.DIAL"); // Create information exchange object Intent | ||
Line 500: | Line 508: | ||
The phone number will be obtained from the field Phone and the text of the message will be obtained from the fields ContactName and Notes. | The phone number will be obtained from the field Phone and the text of the message will be obtained from the fields ContactName and Notes. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
msg = "Dear, " + | msg = "Dear, " + | ||
Line 514: | Line 523: | ||
Suppose a library contains the time and name of an appointment. | Suppose a library contains the time and name of an appointment. | ||
: '''Trigger script:''' | |||
<source lang="javascript"> | <source lang="javascript"> | ||
i = intent("android.intent.action.INSERT"); // Create Intent object | i = intent("android.intent.action.INSERT"); // Create Intent object |