Howto refer to the "Linked from" library in Javascript

179 views
Skip to first unread message

serge...@gmail.com

unread,
Feb 26, 2021, 2:53:23 AM2/26/21
to mementodatabase
Hi,
I am quite new to Javascript and looking for something.
I have 2 libraries.
First one is called invoice and has among others a field "freight cost" (real number) and a link to entry "article lines"
The second one "article lines" has several fields and triggers upon creating and updating.
In those triggers I would like to make some calculation based on "freight cost".
What I am looking for is the manner to refer to "freight cost" from the invoice where I am working on from within the trigger of the linked to library "article lines"
In "article lines" I have no field relating to the invoice those lines are belonging to.
thanks
serge 

Bill Crews

unread,
Feb 26, 2021, 9:12:41 AM2/26/21
to serge...@gmail.com, mementodatabase
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.
--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/031e9968-3cea-4ee2-a361-85dadc2aca9en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages