Triggers: Difference between revisions

11 bytes added ,  7 October 2016
m
no edit summary
mNo edit summary
mNo edit summary
Line 206: Line 206:
var entries = lib().entries();                  // Get current library & array of its entries
var entries = lib().entries();                  // Get current library & array of its entries
if (entries.length > 0) {                        // Check that array is not empty;
if (entries.length > 0) {                        // Check that array is not empty;
                                                 // otherwise exit,
                                                 //   otherwise exit,
                                                 // since there is no previous entry.
                                                 //   since there is no previous entry.
prevMileage = entries[0].field("Mileage");      // The array is sorted newest to oldest,
prevMileage = entries[0].field("Mileage");      // The array is sorted newest to oldest,
                                                 // so newest entry in the array
                                                 //   so newest entry in the array
                                                 // on top with index of 0.
                                                 //   on top with index of 0.
entryDefault().set("StartMileage", prevMileage); // Set value of field Mileage
entryDefault().set("StartMileage", prevMileage); // Set value of field Mileage
                                                 // from the previous entry
                                                 //   from the previous entry
                                                 // as default value for field StartMileage.
                                                 //   as default value for field StartMileage.
}  
}  
</source>
</source>


The script must be set for Event '''Creating an entry''' Phase '''Open the Entry Edit card for Add'''. It will run synchronously.
The script must be set for Event '''Creating an entry''' Phase '''Open the Entry Edit card to Add'''. It will run synchronously.


===== Beginning of the next day =====
===== Beginning of the next day =====