Triggers: Difference between revisions

Jump to navigation Jump to search
847 bytes added ,  23 January 2017
m
no edit summary
mNo edit summary
mNo edit summary
Line 640: Line 640:
-----
-----
<br/>
<br/>
== Built-in Objects Examples ==
=== Example: Extracting coordinates from a Location field into Real fields ===
Suppose you have a Location field called myLocation. If you would like the coordinates as Real fields, create the Real fields, maybe LocationLatitude and LocationLongitude. The create two triggers, as follows:
:; CreateBefore
:: Event: Creating a new entry
:: Phase: Before saving the entry
:: Script: As follows
<source lang="JavaScript">
var e = entry();
var loc = e.field("myLocation");
if (loc.hasNext)
    loc = loc.next();
e.set("LocationLatitude", loc.lat);
e.set("LocationLongitude", loc.lng);
</source>
:; UpdateBefore
:: Event: Updating an existing entry
:: The rest the same as above.
Now, every time you create a new entry or update an existing one, the coordinates for myLocation will be extracted to the Real fields.


== Interaction with the System ==
== Interaction with the System ==

Navigation menu