Memento autofill and library fields

222 views
Skip to first unread message

dts Df

unread,
Mar 4, 2022, 9:40:36 AM3/4/22
to mementodatabase
Hello.
I'm new in this forum and with Memento.
I'm not a javascript expert, but I want to create a test Library that can get from an internet link a currency exchange and then calculate the total price in that currency for a given quantity.

For that, I created the fields Date, Quantidade, Total (script), Nome and Preco.
And then, I created an autofill (trigger ?) script, like the one at the end and shared with the title CurrencyCalc, under dtsbsb account (escuse-me the comments tests).
With this, I can get the correct currency exchange for a date, but my script can't set the field Preco in the Library to calc the Total (Preco * Quantidade).
I think that it's a context error.

Is there any library like this that I can study ?
Thanks in advance.
dtsbsb
Autofill script:
________________________________________________________________________________
var http = http();
lib = lib();
message("Library " + lib.title );
e = entry();
var result = http.get("http:\/\/economia.awesomeapi.com.br/json/last/USD-BRL");
var headerValue = result.header("etag"); //Get response header
//message(result.header("origin"));
message (result.body);
message(result.code + " - código de retorno http");

usdToEur = JSON.parse(result.body) ["USDBRL"]
["bid"];
message("cotação do Dólar em Real = " + usdToEur);
//Preco = usdToEur;
//e.set ( "Preco", usdToEur );
//entry[1].set("Preco") = usdToEur;
message("field Preco = " + e.field("Preco"));
//result(usdToEur);  

//entry().set("Nome", name );

//entry().field("Total") = entry().field("Preco") * usdToEur);
//message("Total = " + entry().field("Total"));

dts Df

unread,
Mar 4, 2022, 9:58:07 AM3/4/22
to mementodatabase
Another question is that:
In android version, there is different result when I create an entry and when I edit the autofill script and, in there, I use the test button.
For this test, I used one of the lines bellow:

message("field Preco = " + e.Preco);

message("field Preco = " + e.field("Preco"));

Bill Crews

unread,
Mar 4, 2022, 10:57:17 AM3/4/22
to dts Df, mementodatabase
I haven't done Autofill in a long time, and I guess I forgot there was a script involved, though I guess there is some adjustment that needs to be done. Is this documented in the Wiki or where?

--
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/63b9c036-8132-45f4-9836-76df38432503n%40googlegroups.com.

Er Mo

unread,
Mar 4, 2022, 12:55:05 PM3/4/22
to mementodatabase
Hallo
Zum Teste von Skripten .
Es ist immer die Frage von WO ich mit den Skript starte . Der Befehl " entry().field("....") " holt den Wert aus den Feld " .... " von Datensatz . Wenn ich dieses Ausführe under "Erstellen eines Eintrages " oder "Änderen eine Eintrage " so ist mein Datensatz den ich erstellt habe oder geändert habe . Teste ich das Skript ,habe ich keinen Aktuellen Datensatz . Ich kann ein Aktions Skript " Einstigsagtion " erstellen das von eine Datensatz aus gestartet wird . Dieser ist mein Aktueller Datensatz .
Es ist auch auf Gruß / Kleinschreibung zu achten .

Hello
For testing scripts .
It is always the question of WHERE do I start the script. The command " entry().field("....") " gets the value from the field " .... " of record . If I run this under "Create an entry" or "Modify an entry" then my record is the one I created or changed. When I test the script, I don't have a current record. I can create an action script "Einstigsage" that is started from a record. This is my current record.
It is also important to pay attention to greetings / lowercase.

Ernst

dts Df

unread,
Mar 4, 2022, 2:18:12 PM3/4/22
to mementodatabase
I read about the context in  Using JavaScript in Memento wiki page.
But finally I have done all I need (get a value from internet and setting a field with this) by inserting this script in the menu Edit/scripts/Add scripts/ Add action   (Memento desktop).


currenceCalc_shot1.png

dts Df

unread,
Mar 4, 2022, 7:01:33 PM3/4/22
to mementodatabase
Good news from now.
I updated my library and its fully funcional in the desktop version.
But in the android version, I received the error http request not available for this runtime.

Is there a way to correct this ?
Reply all
Reply to author
Forward
0 new messages