Hi, Serge. It's great to encounter a new user, especially one who has apparently embraced Memento and is both interested in and capable of learning to use JavaScript to enable the various features of Memento that require the use of JavaScript to use. Welcome to our community of users here on the forum.
Since you are already using triggers to craft your Memento apps, I gather you have already discovered the wiki and its set of JavaScript-related wiki pages. The full set, so far, are JavaScript field under Fields, pages, & subheaders and -- under Scripting, Calculation, & App Integration -- Scripting, Memento JavaScript Library, Tips:Using JavaScript in Memento, Triggers, Trigger Examples, Actions, & Data Sources (which includes discussion of custom data sources).
The central anchor of the JavaScript pages is the Memento JavaScript Library, since all the other pages -- except JavaScript field -- depend on it.
In there, under the Library object, you'll find the following sentence from the 1st paragraph: "You can work with the current library — lib() — or any other library in the database — libByName().". Now, libByName() takes one argument -- the name of the library. Also, as stated in that method: "The library must be set for unique entry names." Also, note the sentence: "Permission to use the library is required, based on security settings."
So, use ...
// Remember to set the library permission & unique entry names
// Set up to reference the invoice library
var libInvoice = libByName("invoice");
... then, something like ...
// Add freight cost into the total
total += libInvoice.field("freight cost");
If you find the need to use the library's entries() method, note that -- contrary to what you might infer from other code contributed in the forum -- it takes no arguments. So, you say ...
var allInvoices = libInvoice.entries(); // No argument
If you have any questions, let us (or me) know. Good luck.