Generate number based on text from another field
Hi all,
I'm trying to automatically generate a field based on 1) a person's name (from a drop-down menu, converted to a number); 2) the date; and 3) a random number. The resulting field would then take on the following (example) value: 10-20170101-1234, where "10" would be an employee's assigned number, "20170101" would be the date (as yyyymmdd), and "1234" would be the random number, with each segment separated by hyphens.
I have the second and third parts, but cannot figure out the JavaScript code to correctly populate the employees' assigned number. An example of what I've come up with so far is:
var date = util.printd("yyyymmdd", new Date());
var person = this.getField("Person").valueAsString;
if (person == "Aaron") event.value = "1";
else if (person == "Amanda") event.value = "2";
else if (person == "Austin") event.value = "3";
if (this.getField("Field").value == "")
this.getField("Field").value = util.printf(person + "-" + date + "-" + "%04d", Math.floor((Math.random() * 10000) + 1));
The "date" and "random number" sections work, but I cannot get the first section to work correctly. If I add a "blank" option (e.g. "if (person== "") event.value = "";) the code will work, and return a blank value for the first segment, along with the correct date and a random number, but that's as far as I've gotten after searching through various forums.
Any thoughts would be much appreciated. Thanks!