|
|
Line 440: |
Line 440: |
|
| |
|
| === System Examples === | | === System Examples === |
| -----
| | See '''[[Trigger Examples#System Examples]]'''. |
| ==== Script to open a screen for dialing a number ====
| |
| Suppose a library contains a field called Phone containing a phone number.
| |
| | |
| :; Add a new trigger: Set Event to '''Opening an Entry View card''', Phase to '''After display of the entry'''.
| |
| | |
| :'''Trigger script:'''
| |
| <source lang="javascript">
| |
| i = intent("android.intent.action.DIAL"); // Create information exchange object Intent
| |
| // with the action of DIAL
| |
| i.data("tel:"+entry().field("Phone")); // The data will be the phone number obtained
| |
| // from the field Phone
| |
| i.send(); // Send the message
| |
| </source>
| |
| <br/>
| |
| -----
| |
| ==== Script to open app to send SMS message ====
| |
| 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.
| |
| | |
| :; Add a new trigger: Set Event to '''Opening an Entry View card''', Phase '''After display of the entry'''. It will run synchronously.
| |
| | |
| :'''Trigger script:'''
| |
| <source lang="javascript">
| |
| msg = "Dear, " +
| |
| entry().field("ContactName") +
| |
| "\n" + entry().field("Notes"); // Form the message from ContactName & Notes
| |
| i = intent("android.intent.action.SENDTO"); // Create intent object to open the app for sending
| |
| i.data("smsto:"+entry().field("Phone")); // Provide the phone number in format smsto:number
| |
| i.extra("sms_body" , msg); // Insert the text of the message to sms_body
| |
| i.send(); // Send the message
| |
| </source>
| |
| <br/>
| |
| -----
| |
| ==== Script to insert an appointment into Google Calendar ====
| |
| Suppose a library contains the time and name of an appointment.
| |
| | |
| :; Add a new trigger: Set Event to '''Creating a new entry''', Phase to '''Before saving the entry'''. It will run synchronously.
| |
| | |
| :'''Trigger script:'''
| |
| <source lang="javascript">
| |
| i = intent("android.intent.action.INSERT"); // Create Intent object
| |
| i.data("content://com.android.calendar/events"); // Data contains Google Calendar URI
| |
| i.extra("title", entry().field("Title")); // Get event name from field Title
| |
| i.extra("description",
| |
| entry().field("Description")); // Get description from field Description
| |
| i.extraLong("beginTime",
| |
| entry().field("Begin").getTime()); // Get start time from field Begin
| |
| // Begin is of type DateTime
| |
| // Additional parameter is of type Long,
| |
| // so extraLong() is used for conversion.
| |
| i.extraLong("endTime",
| |
| entry().field("End").getTime()); // Get end time from the field End
| |
| // Requires same conversion as above
| |
| i.send(); // Send the message
| |
| </source>
| |
| <br/> | | <br/> |
| ----- | | ----- |