Triggers: Difference between revisions

33 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 the current library and an array of its entries
var entries = lib().entries();                 // Get the current library and an array of its entries
if (entries.length > 0) {                           // Check that the array is not empty; otherwise exit,
if (entries.length > 0) {                       // Check that the array is not empty;
                                                    // since there is no previous entry.
                                                // otherwise exit,
prevMileage = entries[0].field("Mileage");         // The array is sorted from newest to oldest,
                                                // since there is no previous entry.
                                                    // so the newest entry already in the array
prevMileage = entries[0].field("Mileage");     // The array is sorted newest to oldest,
                                                    // will be on top with index of 0.
                                                // so the newest entry in the array
entryDefault().set("StartMileage" , prevMileage )   // Set the value of the field Mileage from the previous entry
                                                // on top with index of 0.
                                                    // as the default value for the field StartMileage.
entryDefault().set("StartMileage",prevMileage); // Set value of field Mileage
                                                // from the previous entry
                                                // as default value for field StartMileage.
}  
}  
</source>
</source>