Java script shared scripts

268 views
Skip to first unread message

Bo Br

unread,
Jan 13, 2025, 7:53:00 AM1/13/25
to mementodatabase
I can use the functions from shared script in Action and Trigger scripts. I tried to use them in JavaScript Field, but it don't work (ReferenceError: "SharFun1" is not defined. (field.js#1)).
I can use github, it works, but it is time consuming...
Is it possible and what I'm doing wrong?
Thanks in advance  Bogdan

David Gilmore

unread,
Jan 13, 2025, 11:09:50 AM1/13/25
to mementodatabase
Calling the functions in a "shared" script works for me. Perhaps you could show the script for both the shared function and the button script.

Also, you could try as an experiment the following two scripts. If it works you have confidence that other stuff will also work:

Shared Script:

function SharedScript() {
  message("Shared script has been run");
}

Button script:

SharedScript();

Bo Br

unread,
Jan 13, 2025, 3:01:19 PM1/13/25
to mementodatabase
Yes,thanks, I forgot to mention that I use sh.script in Button Script. As I wrote, it does not work in JavaScript Field, which is much better than Kalulation Field.And yes I am increasingly using Text Fild Updated with Button Script mainly due to efficiency/slowness. 

ponedeljek, 13. januar 2025 ob 17:09:50 UTC+1 je oseba aa6...@gmail.com napisala:

Er Mo

unread,
Jan 13, 2025, 3:43:12 PM1/13/25
to mementodatabase
Hallo
Die Skripte im JS Feldtyp sind nicht mit den Skripten in Auslösern , Aktionen und Schaltflächen zuvergleichen . Es unterscheiten sich schon mal in den Schreibweise und deren Wirkungsbereich ist auf den Eintrag begrenzt .

Hello
The scripts in the JS field type cannot be compared with the scripts in triggers, actions and buttons. They differ in the spelling and their scope is limited to the entry.

Ernst

David Gilmore

unread,
Jan 13, 2025, 4:35:30 PM1/13/25
to mementodatabase
I forgot to ask as to what device are you using? Windows, Android, or iOS?

And did you try the script I gave you?

Bo Br

unread,
Jan 13, 2025, 6:50:07 PM1/13/25
to mementodatabase
Aa6...: My devices are Android 13 (Phone) and 14 (tablet). Did not tried your scripts, I understand them and i use this type since the button field.

Ernst: Procedures can be writen strait forward or build with reusable functions... When using functions, they can be in JS field or in the Shared script or in github or the attached libraries.  
It is mostly about checking the conditions and formating, and, I agree, they are different from the Action or Trigers, where it is more about manipulating data ...  The advantage of scripts is that they are compiled and therefore faster. The use of shared functions also simplifies develop, debuging and maintenance.

My tipical function is:

function formatDate(dt,f){ 
 if( field(dt)==null) return "insert start date"
 return moment(field(dt)).format(f==null ?"D.M.YY" :f)
}

here i set default format and calling is simple :

formatDate("start")

Some checking about dt value can be included.
Such function is a good candidate to be in shared script instead in two or more js Fields.
So, gpt(MS Copilot) says that shared scripts functions can be used in javascript field. But in my case it don't work. I tried calling with 
scriptName.functName()  or just functName()

Regards
ponedeljek, 13. januar 2025 ob 22:35:30 UTC+1 je oseba aa6...@gmail.com napisala:

David Gilmore

unread,
Jan 14, 2025, 1:36:22 PM1/14/25
to mementodatabase
The issue I see is that your function "formatDate" expects two parameters, but your call to that function only has one.

Bo Br

unread,
Jan 14, 2025, 6:21:13 PM1/14/25
to mementodatabase
No, aa6, missing parameters got value null. I check this in function and set value to mostly used format. Try it!

Still noone knows about using shared script functions in js field?

torek, 14. januar 2025 ob 19:36:22 UTC+1 je oseba aa6...@gmail.com napisala:

Mmm

unread,
Jan 15, 2025, 2:13:03 AM1/15/25
to mementodatabase
Варианты:
1. Поместите свою функцию в начало скрипта поля JS. 
2. Разместите файл *.js с функцией в своём публичном репозитарии Github и подключите к полю JS, как библиотеку.

Шаблон с примером:

среда, 15 января 2025 г. в 02:21:13 UTC+3, boo...@gmail.com:
IC_15012025.jpg

David Gilmore

unread,
Jan 15, 2025, 11:48:08 AM1/15/25
to mementodatabase
The problem with forums is that its hard to know if one is a beginner programmer or experienced. I now suspect you are the latter. The reason I mentioned parameters is because it looks like you are expecting a date object as the first parameter, but passed a string instead. I figured the string was supposed to be the second parameter.

As far as your problem, I was thinking that you were talking about a "button" JavaScript script, not the simple inline Javascript field. My bad. As mentioned by both Ernst and Mmm, inline JavaScripts fields run in a separate environment. You can try what Mmm suggested, or move that script into a button's JavaScript field.
Message has been deleted

Bo Br

unread,
Jan 16, 2025, 3:18:59 AM1/16/25
to mementodatabase
 ;) Yes AA6, I'm not exactly expert or profi. Was quite home at Visual Basic in MS Excel. I have been using MDB since at least 2012.
There is a gray field, that is, connecting bases=libraryes. I know the principle of relational bases such as MS Access and I do not understand how it works in MDB. Do you use?
And yes, I asked Vasily about shared scripts. He says it is not currently possible, but after a few hours he added that he would change his mind. 

sreda, 15. januar 2025 ob 17:48:08 UTC+1 je oseba aa6...@gmail.com napisala:

David Gilmore

unread,
Jan 16, 2025, 12:13:17 PM1/16/25
to mementodatabase
Good, Vasily is the one to talk to on this, at this point.

Also, Memento is not considered a relational database like Access is. Any relationship in Memento must be done manually via JavaScript and Linking.

Reply all
Reply to author
Forward
0 new messages