Changes

Jump to navigation Jump to search
1,368 bytes added ,  13:18, 28 June 2021
m
no edit summary
Line 169: Line 169:  
-----
 
-----
 
<br/>
 
<br/>
 +
 +
=== Copying an entry's field values to another library ===
 +
Suppose you use a library to hold purchase orders, and you want a subset of these to be sent to a history library for later transmission to a server database.
 +
:; Libraries: The current library is used as the source library. The target library is to be called PO History. This is set as a default at the top of the script below to copy the current entry to the history library, so the default may be changed readily.
 +
<hr>
 +
:; Fields: My Today's Activities &mdash; Date and Member, a few other fields, and a Checkboxes field called '''Today's Plan'''.<br/>Activity Plans &mdash; A plan name, description, and a Checkboxes field '''Plan''' (identical items to Today's Plan) with the checked activities associated with the plan.
 +
:; Add new trigger: Add two new triggers to the library.<br/>Set Event '''Creating a new entry''', Phase '''Before saving the entry'''.<br/>
 +
<hr>
 +
 +
<source lang="JavaScript">
 +
 +
//Field names to copy to another lib
 +
const fields=["Field1","Filed2"];
 +
 +
// Get current entry
 +
let ent = entry();
 +
 +
//Create empty object
 +
let newLogEntry = new Object();
 +
 +
//Get another library name and create new entry
 +
let logs = libByName("anotherLib");
 +
let newEntry = logs.create(newLogEntry);
 +
 +
 +
//Fill new log entry with values from state
 +
for (let i of fields) {
 +
    newEntry.set(i,ent.field(i));
 +
}
 +
</source>
    
== Files Examples ==
 
== Files Examples ==

Navigation menu