Autofill data based on last entry + integer

247 views
Skip to first unread message

Teresa Flores

unread,
May 4, 2023, 1:04:26 PM5/4/23
to mementodatabase
Hello, I am brand new to this so forgive me! We are creating a simple inventory logging system using Memento Database. We include three things in each entry: 1. Customer name, 2. Inventory number, and 3. Photo of the object. I'm hoping there is a way to set up the application such that the Customer Name and Inventory Number field can autofill with the last entry's data every time a new entry is created.

My main questions
:

1. For the Customer Name field: is there a way to accomplish this without having to begin typing the customers name every time? Can the name just appear there based on the last entry?

2. For the Inventory Number field: can this be set up as an integer field that auto-populates with the next sequential number when a new entry is created? For example, if the last entry was inventory number 450, can the inventory number field on the new entry be autofilled with "451"?

Thank you in advance!

Er Mo

unread,
May 4, 2023, 1:54:19 PM5/4/23
to mementodatabase
Hallo
Mit einem Skript ist das Alles möglich . Mir stellt sich aber die Frage nach der Sinnhaftikeit . Wenn du mehr mit Kunden zu tun hast würde ich gleich einen eigene Kunden Bibliothek einrichten ( mit Name , Attresse , Tel ,...) und auf diese Verlinken .

Hello
It's all possible with a script. But the question of meaningfulness arises for me. If you have more to do with customers, I would set up your own customer library (with name, address, phone,...) and link to it.

Ernst

Teresa Flores

unread,
May 4, 2023, 3:56:15 PM5/4/23
to mementodatabase
Thank you! I was able to set up a Customer library and use the autofill feature to allow our staff members to search and select the correct customer. However, is there a way that I can set this up so it remembers the last customer that was selected? And automatically fills in that customer's name on the next entry? Our staff will be making 50+ entries per customer, so searching the name everytime will be a burden. Thanks!

Er Mo

unread,
May 4, 2023, 4:19:32 PM5/4/23
to mementodatabase
Hallo
Willst du die 50 Einträge auf einmal machen oder sind sie auf Tage / Wochen  verteilt . Memento kan Einträge " Automatisch " erstellen oder von einer Liste abarbeiten .

Hello
Do you want to make the 50 entries at once or are they spread over days/weeks. Memento can create entries "automatically" or process them from a list.

Ernst

Teresa Flores

unread,
May 4, 2023, 4:35:39 PM5/4/23
to mementodatabase
They will be entered one-by-one because the staff member is on-site with a customer and taking photographs of objects which we will sell in our auctions. So we are logging each item as an entry in the database, with the inventory number and a photograph. So, when a staff member is on-site with a customer, they will need to make lots of entries, one-by-one, and it would be very helpful if the app could remember the customer's name from the previous entry to avoid searching for it every time. Do you have any suggestions or a way to format the script? Thanks so much for your help!

Bill Crews

unread,
May 4, 2023, 4:52:18 PM5/4/23
to Er Mo, mementodatabase
On the inventory number, set as Integer field with Default as Autoincrement and set in the MAIN tab as Unique field.

On the customer name, there is the specific case of your focused data entry process, and there's the general case, where you might edit an entry or otherwise deal with a different customer from the last one. You should be able to do both, but the plan to prepopulate with previous customer name likely wouldn't apply in the update case.

Ideally, you should use scripting to switch modes and manage this process. If you don't have scripting experience, at least handle the inventory number field.


--
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/d50fd26b-97b5-4e15-97e8-a902e9cc9a0an%40googlegroups.com.

Teresa Flores

unread,
May 4, 2023, 5:14:42 PM5/4/23
to mementodatabase
Thank you! I appreciate your response. I was able to get the inventory number integer working. Is it possible to have the customer names pre-populate from the last entry, but still have it as a searchable field in case the staff member needs to switch to a different customer? I am not well versed with script so if you have any suggestions for a workaround or perhaps a resource I can contact for help with developing this script, I would greatly appreciate it. Thank you!

Bill Crews

unread,
May 4, 2023, 8:43:41 PM5/4/23
to Teresa Flores, mementodatabase
Go into Scripts and press the blue + button. Then select Trigger. Now you have a Trigger card to fill out. At the top, name the trigger to your liking, then leave the defaults as they are: Entry and Opening an Entry Edit card.

Then in the script editor section of the card, enter the following...

let entries = lib().entries();
if (entries.length > 0) {
    entryDefault().set("Customer name", entries[0].field("Customer name"));
}

Then press the checkmark in the upper left corner to save the trigger. The 1st statement gets all the saved entries into an array that can be indexed from 0 to length - 1, with 0 being the most recently created entry. The if statement checks to see if there are any of those saved yet. If so, it gets the customer name from the most recent entry and puts it into the new entry, as you want it.

In case you want to skip that this time, but since it's already done, you could create an entry action to clear the customer name field by pressing a button, so you don't have to do that manually. For this part of the solution, while still in Scripts, press the blue + button again and then select Action to create a field-clearing action. When the action card displays, name it to your liking, and change Library to Entry at the top of the card. Then in the script editor, type the following...

entry().set("Customer name", null);

Then press the checkmark at the upper left of the card to save the action.

So, now, when you add the first entry to your library, it'll work normally, since there was no previous customer. For the 2nd, the customer name will fill in when you start to add the entry. If you decide "not this time", press the little Play button near the top of the card to clear the customer name.

The following library implements it...


Teresa Flores

unread,
May 5, 2023, 9:56:38 AM5/5/23
to Bill Crews, mementodatabase
Thank you so much Bill. I was able to get the Customer's name to repopulate. I can't seem to get the play button to appear for the reset option. Do these settings look correct? Note: the customer name field is called "Consignor":

Screenshot 2023-05-05 at 9.50.31 AM.png

One final question: is there a way to remove the comma from the integer field on the mobile version? Our inventory numbers are appearing as 45,620 instead of 45620, for example. Thank you again for your help!

Er Mo

unread,
May 5, 2023, 12:05:09 PM5/5/23
to mementodatabase
Hallo
Der " Play Pfeil " ist im Eintrag sichtbar . Oben rechts . Das Skript ist füe einen Eintrag uns nicht für die Ganze Bibliothek .

Hello
The "play arrow" is visible in the entry. Top right . The script is for one entry and not for the whole library.

Ernst

Bill Crews

unread,
May 5, 2023, 12:22:15 PM5/5/23
to Teresa Flores, mementodatabase
On Fri, May 5, 2023, 09:56 Teresa Flores <florest...@gmail.com> wrote:
I was able to get the Customer's name to repopulate. I can't seem to get the play button to appear for the reset option. Do these settings look correct? Note: the customer name field is called "Consignor":

Screenshot 2023-05-05 at 9.50.31 AM.png

The instructions I gave were for the mobile edition. I see now you're using the desktop edition. When your people are with customers, which edition are they on? I was imagining them "in the field" and using a mobile device.

On this screen, the Play button is labeled as Run, because you're in developer mode here. If you have the entry itself (in user mode) before you, the Play button is not labeled, but it appears as a standard Play button (like in YouTube) without a label.

As for the inventory number, Memento doesn't put commas into integers, so you must be using a Text field or importing or something. I assume you're not needing to calculate with the inventory numbers, so a Text field should work fine, but with a Text field, there is no option to autoincrement the number, and if there are commas in the numbers, your people must be adding them themselves!

Option 1 would be for them to save the keystroke and not type it in. Option 2 would be for you to use an autoincrement Integer field instead of a Text field, and commas would not be able to be entered. Option 3 would be for a script to remove any commas from a Text field. So, assuming you keep it as a Text field, we need in the script to autoincrement the number even though it is a string rather than an Integer, and we need to remove commas.

It sounds to me like you need to learn some JavaScript. Do 2 things...
    1. On an Android device, go to the Google Play store and install Grasshopper, the app for learning JavaScript. Then take the 1st 2 courses, called Fundamentals 1 and Fundamentals 2.
    2. Search the forum for messages whose subject line starts with "Bm". These are my "Bill's mementos" -- newsletters that for most of not all of this year contain articles that are chapters of Beginning Memento JavaScript for Nonprogrammers. They are sent more or less monthly, though I missed both March and April. The May issue will be coming out very soon with chapter 3 of the course, which starts to move you into objects. It goes very slowly, but that seems to be what beginners need, so it'll take all year to finally get to all the tricks you might want, but it'll be worth it if you frequently have needs for customizing your use of Memento.

I'll update the Teresa library with a Text field for the Inventory number and a new script to do the comma stripping and autoincrementing. When you see the Text field and a comma-stripping script appear, I'll be done, and see what you think. I'm doing everything on Android devices, as that's what I have and use. Something could be slightly, annoyingly different on the desktop edition. Give me some hours. I have to eat and run errands today, but I'll get to it.

Er Mo

unread,
May 5, 2023, 1:47:33 PM5/5/23
to mementodatabase
Hallo Bill
Das mit den Komma ist wohl ein " Tausender punkt " . Der wird nach 3 Stellen gesetzt um die Lesbarkeit zu verbessern . Ist aber auch Länderspezifisch . Glaube das man den auch Abschalten kann .

Hello Bill
That with the comma is probably a "thousand point". It is set after 3 digits to improve readability. But it is also country specific. I think you can turn it off too.

Ernst

Bill Crews

unread,
May 5, 2023, 3:10:55 PM5/5/23
to Er Mo, mementodatabase
Good point. But in the English version, the only spacing option (other than none) is to insert spaces at the thousands break, and even then, if you fetch and try to make use of the value, it's merely the integer again. I bet in the German-language version, the value is returned as an integer and thus without commas, as in my version, no?


Er Mo

unread,
May 5, 2023, 3:30:29 PM5/5/23
to mementodatabase
Hallo Bill
Ich glaube dass NUR die Anzeige geändert wird und nicht der Speicherinhalt

Hello Bill
I believe that ONLY the display is changed and not the memory content

Ernst

Bill Crews

unread,
May 5, 2023, 3:50:22 PM5/5/23
to Er Mo, mementodatabase
Exactamente, por lo que en un campo Integer, nadie verá ninguna coma, punto o espacio, sino solo un valor entero.  Es la conversión de entero a cadena y viceversa donde los errores pueden aparecer. Estamos sincronizados en esto.

Realmente no sé de dónde vienen las comas de Teresa, porque no creo que sea de Memento, a menos que sea solo visualmente Y ella vive donde una coma puede separar miles.  Uno de sus ejemplos tenía la coma en la posición final, lo que realmente me deja perplejo.  ¿Parece que su gente podría estar escribiéndolos?
__________

Genau, also in einem Integer-Feld wird niemand jemals Kommas oder Punkte oder Leerzeichen sehen, sondern nur einen Integer-Wert.  Es ist die Umwandlung von Integer in String und zurück, bei der sich Fehler einschleichen können. Wir sind uns darin einig.

Ich weiß wirklich nicht, wo Teresas Kommas herkommen, weil ich nicht glaube, dass es von Memento ist, es sei denn, es ist nur optisch UND sie lebt dort, wo ein Komma Tausende trennen kann.  Eines ihrer Beispiele hatte das Komma an der letzten Position, was mich wirklich verwirrt.  Es scheint, dass ihre Leute sie tatsächlich tippen?
__________

Exactly, so in an Integer field, no one will ever see any comma or period or space characters, but only an integer value. It's the conversion from integer into string and back that the errors can creep in. We are in sync on this.

I really don't know where Teresa's commas are coming from, because I don't believe it's from Memento, unless it's only visually AND she lives where a comma can separate thousands. One of her examples had the comma in the final position, which really perplexes me. It seems her people might be actually typing them?

Bill Crews

unread,
May 5, 2023, 4:40:14 PM5/5/23
to Teresa Flores, mementodatabase
One final question: is there a way to remove the comma from the integer field on the mobile version? Our inventory numbers are appearing as 45,620 instead of 45620, for example. Thank you again for your help!

First, I don't know where you're located, but Ernst is in western Europe, and I am on the east coast of North America. So, Ernst & I have different settings for decimal points & thousands separators, among other things. What is your region of activity? Attached is the Integer field add card I see here in North America. As you can see, if there are any thousand separators, it has to be spaces, which is not the normal for my region (which would be commas). I've always assumed (maybe wrongly) that Memento used spaces for thousands separation everywhere to avoid the complexity of handling regional differences. Of course, integers don't have decimal points.

My question is: Is your Inventory number field an Integer field, and if so, what is the setting on mobile for Thousands separators in your field add card? Maybe you have commas as a choice? If so, you could turn that off.

I'm playing with scripts involving replacing characters in string versions of numeric fields and so on, but I'm not sure if you even need this, and I'm still working out some difficulties with it, so if I'm on the wrong track, it'd be nice to know that soon. I really don't understand where the commas are coming from.
Screenshot_20230505_162143_Memento Database.jpg

Teresa Flores

unread,
May 8, 2023, 10:20:58 AM5/8/23
to mementodatabase
Hi Bill and Ernst, thank you for your replies! 

I am located in Toronto, Canada. Here is a screenshot of my mobile settings for the "integer" field. I don't see the thousands separator option here. We are not manually inserting any commas, they just appear automatically in any number >1000. 

IMG_5392.PNG

Bill Crews

unread,
May 8, 2023, 12:17:34 PM5/8/23
to Teresa Flores, mementodatabase
I think you should contact sup...@MementoDatabase.com, though you'll probably just get a terse description of how it come to have inserted commas, with no option to do otherwise. If it has to be this way, let me know, and I'll figure out how to make it a Text field, but still do autoincrement and so on without separators. I started to do it a couple of days ago, but it looked to be messy. JavaScript Number objects (like Memento Integer fields) have methods like parseInt() and toString() that are probably enough to handle it, but we'll see.

Er Mo

unread,
May 8, 2023, 12:53:25 PM5/8/23
to mementodatabase
Hallo
Ein Versuch wäre noch das Betriebssystem zu Ändern . Vielleicht im Betriebssystem die Einstellung ändern .Ob sich Memento danach richtet.

Hello
Another attempt would be to change the operating system. Maybe change the setting in the operating system. Whether Memento is based on it.

Ernst

Bill Crews

unread,
May 14, 2023, 12:37:59 AM5/14/23
to Teresa Flores, mementodatabase
Teresa, I'm sorry it took me so long, but if you're willing to make the inventory number a Text field instead of an Integer field, I've written the code to autoincrement the number and populate the new entry with the customer name from the previous entry and the incremented inventory number (from the previous entry. You have the link already, but you might want to download it again. Here's the link. The main operative script is Fill from previous entry, but there's also an entry action (button) to clear the customer name, in case that helps. I think this solves the problem. Here's the link again...



On Mon, May 8, 2023, 10:21 AM Teresa Flores <florest...@gmail.com> wrote:

Teresa Flores

unread,
May 16, 2023, 1:50:40 PM5/16/23
to Bill Crews, mementodatabase
Thank you so much Bill! I do not have an Android device - I'm using iPhone - but I am visiting a friend this week who can lend me an Android device to test this. I really appreciate your help.

Bill Crews

unread,
May 16, 2023, 3:39:26 PM5/16/23
to Teresa Flores, mementodatabase
Since the beta testing period of the iOS platform was over, I've never used Memento on an iOS device, so I'm not sure, but the scripts in the library I linked you to should be valid on all editions & all platforms, so I don't think you need to wait.

Teresa Flores

unread,
Jun 28, 2023, 3:08:22 PM6/28/23
to mementodatabase
Hi again Bill! I am trying to locate the script on the library sample you sent me. I would like to use the text string for the inventory number and use script to autoincrease that number by +1 from the previous entry, as you described above. I have the library open on my Android device, but I cannot find where the script is located to take a look at it. I cannot click on "edit library" as it says "only the owner can change the structure of the library". Could you please let me know what the script would be to accomplish the auto-increment based on previous entry? Thank you so much for your help! And my apologies if I am missing something blatantly obvious (large likelihood..haha). 

P.S: Until now, I was using the autoincrement feature with the integer field, but there are cases where we need to revert back to an older sequence of lower numbers, and the autointeger switches back to the highest recorded number everytime a new entry is created, defeating the purpose.

Bill Crews

unread,
Jun 28, 2023, 4:23:48 PM6/28/23
to Teresa Flores, mementodatabase
The scripts are in the right-side (3-dot) menu. Scroll down from Edit Library to near the bottom for Scripts. If you're not allowed to view or edit, then you need to copy the entire library, thus making the copy your own. Then, you should be able to see & edit it.


Teresa Flores

unread,
Jun 30, 2023, 9:30:15 AM6/30/23
to mementodatabase
Ah yes - I had to make a copy of the library. The code worked perfectly, thank you Bill!
Reply all
Reply to author
Forward
0 new messages