JavaScript VLOOKUP

284 views
Skip to first unread message

Aaron Dahl

unread,
Sep 27, 2018, 6:30:03 PM9/27/18
to mementodatabase
Howdy All!

I've been struggling with some javascript functions for our small team application. One of the tasks I've been struggling with is a "vlookup" type function using JavaScript.

Within my Activities library, I have long been able to capture the MDB username, but we really need the actual name of the user who is inputting the information. I came up with the following as a comparable to VLOOKUP in gsheets, where you effectively define a static array, then you pass some search criteria in it to locate the relative value in column 2. Just sharing this information for others in search of a similar function.

var e = entry ();
var login = e.author;

var data = [
    ["jessieduke", "Jessie Duke"],
    ["boduke", "Bo Duke"],
    ["daisyduke", "Daisy Duke"]
  ];
function search(searchValue1) {
  var i;
  for (i = 0; i < data.length; i++) {
    if (data[i][0] === login) {
      return data[i][1];
    }
  }
}
var result = search(login);
e.set ("Entrant", result);
//message(result);

I realize I can set up another field and do a calculation, but "boduke" does no one any good, and it will always have to be transferred. There are also other industry standards that never change that I would like to reference without them having to be a completely separate library. I know there will be other uses in our organization for this similar function. I am certainly open to suggestions for making this code more efficient.

Cheers!

Aaron Dahl

unread,
Sep 29, 2018, 10:24:03 AM9/29/18
to mementodatabase
So, I thought all works well with this, but now for some reason, I have determined this (and other scripts) are not working on the mobile edition. It all works fine on the desktop app, but most of the use for this application will be in the field. It's obviously more convenient to script using my desktop, but how do I "scrub" the code to make sure it works in the mobile version?

~Frustrated.
Reply all
Reply to author
Forward
0 new messages