Accesing entry in other lib

157 views
Skip to first unread message

kom...@gmail.com

unread,
Jan 14, 2018, 9:35:25 AM1/14/18
to mementodatabase
Hey. I'm fresh user. I have made many different tries to resolve my problems and I did research and read wiki couple of times as support when doing triggers and libraries. I know i should think different but all knowledge I have is about relational databases since I have no idea how use memento in other way for task i want. I havent done many relational databases (most for school) so my tables can be wrong.
My x attempt have these libraries and fields.

Lib:
Inventory v2
-ID Item
-Item
-Quantity

Lib:
Location
-ID Location
-Location

Lib:
Description
-ID Location (needed, link to entry Location)
-ID Item (needed, link to entry Inventory v2)
-Used (quantity of used items at that location)
-Note (if I want to write note about this usage)


Question is: How do I access that one I marked with orange.
Task: I want to prevent myself from deleting Item (if I throw it away or something) when I have one or more of (this thing I marked orange)

If my way of thinking is wrong so I look forward for response to that instead.

I found that memento javascript cant delete rows (that throwed other idea away)

Screenshot_2018-01-14-15-12-48-1-1.jpg

Bill Crews

unread,
Jan 14, 2018, 12:04:41 PM1/14/18
to kom...@gmail.com, mementodatabase
I know i should think different but all knowledge I have is about relational databases since I have no idea how use memento in other way for task i want.

Using Memento relationally should generally work fine, though there is no SQL engine for it, so you're left with the user interface and scripting as your tools.

Lib:
Inventory v2
 -ID Item
 -Item
What type is Item? What goes in there? An item name as opposed to its ID Item, which is a code?

 -Quantity
Is this quantity the total Used across all locations? If so, we might need to talk about how it stays up to date.

Lib:
Location
 -ID Location
 -Location
What type is Location? What goes in there? A name vs the ID Location code?

Task: I want to prevent myself from deleting Item (if I throw it away or something) when I have one or more of (this thing I marked orange)
So, I understand you have 3 items, each of which are 2m TV cables? So the Description library represents all the products you carry, as a rule, so you don't want to delete your last item of that description?

I suggest to define a Deleting an entry Before saving trigger in your Inventory library. The script should cancel() if there are any entries in Description that link to the item. Doing that would entail something like the following:

var descLib = libByName("Description"); // Have to authorize this
if (descLib == null) {
   message("Description library not found");
   cancel();
   exit();
   }
var descs = descLib.entries();

var item = entry();
var id = item.field("ID Item");

for (var desc in descs) {
   if (descs[desc].field("ID Item") == id) {
      message("Error - Item still in Description library");
      cancel();
      }
   }

To authorize access to the Description library, press the shield icon in the top bar of the script editor. I hope I had no errors; I didn't test.

I found that memento javascript cant delete rows (that throwed other idea away)
If you decide to use this, what you can do is make a structure copy of the library and then add only the entries you still want into the copy, effectively deleting those you didn't add.

Adorable Wolf

unread,
Jan 14, 2018, 12:41:24 PM1/14/18
to mementodatabase
Hey, appriciate for you answer, still at Sunday :o

Let me try to answer all you asked here step by step:


"
Lib:
Inventory v2
 -ID Item
 -Item
What type is Item? What goes in there? An item name as opposed to its ID Item, which is a code?"

Item is "text" type and is used as name. In main(Not this lib, but same idea of project) I'm using more fields and categories to sort out items I have, cables, mouses, keyboards. Example fields: Color, length and so on -> some of these go as "Name" when displaying it to me so I have all details I need to recognize/distinguish item from other. ID is just INT that goes up by 1 each time I make new item. ->Possible mistake from SQL based idea since connections between libraries are using their own ID actually.
----------------------
"
 -Quantity
Is this quantity the total Used across all locations? If so, we might need to talk about how it stays up to date."

Quantity is supposed to tell me TOTAL amount of item that kind I own. -> Simply said. Buying third cable that I already own 2 of. I simply open it, add 1 item to this(TOTAL -> 3) so there is no problem with holding it up to date.
-------------------
"
Lib:
Location
 -ID Location
 -Location
What type is Location? What goes in there? A name vs the ID Location code?"

Location is simply text that explain me in which location I can find cable that I've used already to something but need to get it to do something else.  Let's say.. I have like 20cables at my PC and 10 at my TV spot(receiver and so on). I have this library to add at ease new locations like Bedroom TV or even that i lend it to someone else.
ID is again meant from SQL to have it's unique ID. Not sure actually if I should keep these at all. Autoincrement by 1.
---------------------
"
Task: I want to prevent myself from deleting Item (if I throw it away or something) when I have one or more of (this thing I marked orange)
So, I understand you have 3 items, each of which are 2m TV cables? So the Description library represents all the products you carry, as a rule, so you don't want to delete your last item of that description?"

Yes. 1 "item" can be made of "x" exact same. BUT i want to prevent removing that "item" from list on Inventory v2 so long I haven't removed all descriptions. I don't want to own excess of "waste", after removing some of items, in Description Library.
--------------------
Yeah, I know power of cancel() to prevent me do deleting BUT I have no idea how to check IF I still have any description for that item I want to delete if I'm in hurry and I forget about it(idiot safe?). Since I can do tests only on Description side for linked entries. I have no idea how to do it from Inventory and if it is possible at all. I have used many nights to figure out how Memento works since, as said, it isn't my main "way" to do it.
--------------------
"authorize access"

I got it so far from my exploring in Memento :) 
------------------------
"
I found that memento javascript cant delete rows (that throwed other idea away)
If you decide to use this, what you can do is make a structure copy of the library and then add only the entries you still want into the copy, effectively deleting those you didn't add."

I know I can just copy entries I want but I wanted to javascript/triggers do the job so I hadn't to create new library each time I would remove 5 items. -> I know, I can do it manually from trash. But I searched this "forum" and I found that it isn't possible but I checked it only when I had no more ideas how to progress.

I hope it explain little more eh? :)





Bill Crews

unread,
Jan 14, 2018, 1:08:44 PM1/14/18
to Adorable Wolf, mementodatabase
We are just users/designers talking; there is no right or wrong way; just different people at different times with different requirements.

In large organizations, with lots of developers & users who come and go over years, we got in the habit of encoding keys. Fine, but for me now (no organization or very small), I prefer to just make sure my names are unique and not use codes. That's just me now. Codes are fine, if you feel you need them. You can set Unique Entry Names on the Main tab in the Memento library edit screen. Not different in SQL, actually.

I have no idea how to do it from Inventory and if it is possible at all. I have used many nights to figure out how Memento works since, as said, it isn't my main "way" to do it.

So, I guess my code was not convincing. I thought it would do what you wanted.

What I didn't do is check that the descriptions linking to an inventory item had the same description as each other. If two descriptions with different names link to the same inventory item, what happens? Which one is the master? You can't tell from the Inventory library.

Adorable Wolf

unread,
Jan 14, 2018, 1:29:24 PM1/14/18
to mementodatabase
"We are just users/designers talking; there is no right or wrong way; just different people at different times with different requirements.

In large organizations, with lots of developers & users who come and go over years, we got in the habit of encoding keys. Fine, but for me now (no organization or very small), I prefer to just make sure my names are unique and not use codes. That's just me now. Codes are fine, if you feel you need them. You can set Unique Entry Names on the Main tab in the Memento library edit screen. Not different in SQL, actually."

Actually in my "main" testing project I haven't used ID's at all since Name is already set up as unique(not via unique tab but just usage of few fields that fills up name)
------------------------------------------------
"
I have no idea how to do it from Inventory and if it is possible at all. I have used many nights to figure out how Memento works since, as said, it isn't my main "way" to do it.

So, I guess my code was not convincing. I thought it would do what you wanted."

Firstly. I removed entry this way-> Open entry-> ... -> remove (no prompt up) (I think this is modyfing, so I just need to make almost same trigger for this so this is not a problem)
Second I tried to remove by just tapping on entry, holding down and then remove(prompting if im sure) and this gives me error: 
ID Item not defined, referance error- > I think I will need to think about this one, maybe I have something wrong in my db
---------------------
"What I didn't do is check that the descriptions linking to an inventory item had the same description as each other. If two descriptions with different names link to the same inventory item, what happens? Which one is the master? You can't tell from the Inventory library."

Not sure what do u mean here? 

In general Inventory v2 is MAIN one that I will use to add new items. "Description" is only to tell how many are left to use and give any note to this.
Firstly I make Location and Item and theeen I can create Description by linking up these two(i need to select them first). I don't want to create description for every item I make and this is the reason I put link to entry FROM description to Invetory v2 and Location.



Message has been deleted

Adorable Wolf

unread,
Jan 14, 2018, 2:32:40 PM1/14/18
to mementodatabase
From "message()" tests it looks like that: 
item.field is getting number out 
descs[desc].field("ID Item") is giving me an object instead. 

I got to work locally in javascript field to get number out.. but somehow I can't get it to work on script.

Adorable Wolf

unread,
Jan 16, 2018, 2:32:48 PM1/16/18
to mementodatabase
Your code didn't work in 100% BUT after some tweaks I got it to work as I wanted.

descs[desc].field("ID Item")[0].field("ID Item") did the job :D


Thanks ;)
Reply all
Reply to author
Forward
0 new messages