Triggers: Difference between revisions

10 bytes added ,  7 October 2016
m
no edit summary
mNo edit summary
mNo edit summary
Line 204: Line 204:


<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
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>