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!