auto filing from a local source

168 views
Skip to first unread message

Jude Daniel

unread,
Dec 20, 2017, 4:30:26 PM12/20/17
to mementodatabase
finding it hard autofilling from another lib with the name stock
i do not know how to modify the script and how to map the custom source to my current lib.
any one with help ?

var anotherLib = libByName(“AnotherLib”) // Replace with yours
var entries = anotherLib.find(query);
var resultArray = [];
for(var i in entries ) {
var object = {};
object[“title”] = entries[i].title;
object[“desc”] = entries[i].description;
object[“number”] = entries[i].field(“Number”); // Replace with yours
resultArray.push(object);
}
result(resultArray);

Bill Crews

unread,
Dec 21, 2017, 1:01:58 AM12/21/17
to mementodatabase
Well, I see you are trying to use the example script in the Data Sources wiki page, which is the right place to be. You haven't said what doesn't work, so I can't help you.

Jude Daniel

unread,
Dec 21, 2017, 1:36:45 AM12/21/17
to mementodatabase
thank you bill, don't know how to integrate my lib name or the field name into the script, so the debug keep showing an error message, i'm new with java but do not want to let go
this is what i did

var anotherLib = libByName(“STOCK”) // Replace with yours
var entries = anotherLib.find(query);
var resultArray = [];
for(var i in entries ) {
var object = {};
object[“title”] = entries[i].title;
object[“desc”] = entries[i].description;
object[“number”] = entries[i].field(“product id”); // Replace with yours
resultArray.push(object);
}
result(resultArray);

Bill Crews

unread,
Dec 21, 2017, 4:02:37 AM12/21/17
to Jude Daniel, mementodatabase
don't know how to integrate my lib name or the field name into the script, ...

var anotherLib = libByName(“STOCK”)          // Replace with yours

That was right, assuming you have a library called STOCK that has data in it you want to Autofill with. As with all libByName() calls, you need to authorize the library in the script editor, or it won't work. -bc

so the debug keep showing an error message, i'm new with java but do not want to let go
 this is what i did

The language is JavaScript. Memento itself is written in Java, which was developed by Sun and is now owned by Oracle. JavaScript was developed by Netscape and is now standardized and administered by Mozilla. DIFFERENT. You don't need to know ANY Java and not much JavaScript, either. -bc

It's good that you told me you got an error message, but I still don't know enough to help without your telling me what the error message was. -bc

Not wanting to let this go is the single best quality you can have to become successful at programming. -bc

var entries = anotherLib.find(query);
var resultArray = [];
for(var i in entries ) {
   var object = {};
   object[“title”] = entries[i].title;
   object[“desc”] = entries[i].description;
   object[“number”] = entries[i].field(“product id”); // Replace with yours
   resultArray.push(object);
   }
result(resultArray);

The way Autofill works, it wants this array, here called resultArray, of objects with values for these specific property names: title, desc, and number. It will fill your library's field values from these properties based on the Autofill mapping you create in Autofill.

That's all I know to say, but here's a quick lesson on debugging scripts in Memento...

In the script editor, on the top bar, just above the script edit pad, you'll see some icons. One is a shield. Use it to identify things you want to do to external things. Authorize your STOCK library here, or else libByName() will fail.

Another top bar icon is the Play button. Use it when you're done typing in your script and before you exit the editor. It tests the script. You get a line that says "successfully" in it, or else it fails with a bunch of lines. If it fails, there's no need to waste time trying to move on; you need to fix it until you get "successfully".

If it fails, you get a bunch of lines, but totally ignore all but the first one. It has an error message that I'll need to see before I can help you. And it tells you where the problem is with a thing at the end like JS#1. The 1, just as an example, would refer to the first line, the libByName() call. Unfortunately, the script editor doesn't show line numbers, but you can count. Two quick rules for counting lines: (1) Blank lines are counted. (2) Long lines that wrap and make two lines on your screen count as just one line.

So, if you make sure your script is authorized to access STOCK, run the script with the Play button, probably will not get "unsuccessfully", send me the script text (again), and send me the first of the error message lines, THEN maybe I can start helping you.

Jude Daniel

unread,
Dec 21, 2017, 6:06:38 AM12/21/17
to mementodatabase
here is the screen shot of the error message .
i truly appreciate you bill for all ur response 
BlueStacks_ScreenShot.jpg

Bill Crews

unread,
Dec 22, 2017, 11:55:39 AM12/22/17
to mementodatabase
Again, only the first error message line really matters, so you have an illegal character in the first line ("js#1").

Assuming the libByName() call is your first line, I do notice that there is no semicolon act the end of that line; it should have one. I don't see any other problem with it.

So try adding a semicolon right after the close parenthesis character and see what happens. "Illegal character" doesn't sound right to me for that, but you never know how a parser will sense a problem; the error message sometimes doesn't make a lot of sense, though it usually does.

Logan (DarkComet)

unread,
Jan 2, 2018, 9:05:57 PM1/2/18
to mementodatabase
You got a syntax error. When you search for the error you got you'll want to reference the developer reference guide by Mozilla and it explains it is because of a incorrect character.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Illegal_character

Wiki websites and some word editors use what is called "non-standard quotation marks" where the opening double quote is different than the closing double quote. This is usually for aesthetics, however when you copy the example code from the wiki page and past it into the script editor you'll get an error because one of the quotes is not an acceptable character for the debugger.

So change the ("") for all of the quotes by retyping them. As long as your not using a word processor or something that would change it, your keyboard (on your smartphone, computer, etc...) should use "simple quotation marks".

Hope this helps! Got the same error and that is what I did to fix it.

- Logan (DarkComet)

Bill Crews

unread,
Jan 3, 2018, 7:23:15 AM1/3/18
to Logan (DarkComet), mementodatabase
You're right. That kind of thing can happen. In this wiki, all quotes are matched by the same type, usually double-quotes. But who knows what can happen during cut'n'paste, especially if you use Paste Special?

However, it is also the case that script error messages, while sometimes descriptive of the true problem, are often seemingly gibberish, because your error confused the parser, and it tripped over something else in its confusion. In this case, there is a missing semicolon on the first line. That is my fault; it was in the wiki that way, for some reason. I would fix that first, and if there are no other known simple errors, then consider possibilities like this.


Reply all
Reply to author
Forward
0 new messages