How to reference linked field in a script

101 views
Skip to first unread message

Max

unread,
Dec 27, 2017, 4:20:23 AM12/27/17
to mementodatabase
Hi All

I use the DB for basic transaction management or an online shop. I am trying to optimize with scripts.

I have the following (simplified) structure:

Libs:
Contacts
Transactions

An entry transaction has a link to an entry in Lib "Contacts".

When running a script in Lib Transactions, how can I reference the linked entry?

Such as:
//create a new entry in Lib Transactions with data from current entry

var e = entry();
var transactions = libByName("Transransactions");

var newTransaction = new Object();

newTransaction["email"] = e.field("email");
newTransaction["Contacts"] = e.field("Contacts");

transactions.create(newTransaction);


Furthermore, is there a way to link entries within a script?

Thanks
Max

Bill Crews

unread,
Dec 27, 2017, 6:52:43 AM12/27/17
to Max, mementodatabase

Is email an Email Address field, a Text field, or what? Likewise, is Contacts a Contact field, a Link to Entry field, or what? Setting values based on what is returned from a function or method may work fine or not. What is returned may be just the text of a name and not the entire JavaScript object for the field type. My guess is that email might work right, but if Contacts is a Link to Entry field (or even if it is a Contact field), it may not.

For example, the field() method returns an array of Entry objects for a Link to Entry field.. When that is used as input to create(), I'm not sure what happens is what you want.

Furthermore, is there a way to link entries within a script?

I recommend you read the Memento wiki page entitled Memento JavaScript Library and go to the Object Entry section. You'll see the field() method there, including a revealing table of return values. You'll also see there the link() and unlink() methods. This may answer some of your questions.

Keep in mind that functions and methods in JavaScript return whatever the author thinks will be a useful value for callers and not necessarily native objects. Some argue they should, but some argue the other way, as well.
Reply all
Reply to author
Forward
0 new messages