Thank you! It worked, had to change the field name from name tot Wetenschappelijke naam, but then I got my plantcodes.
It now creates the code from the first two fields, so two characters. Is it difficult to create it with the first three fields, to get a three-characters code. The code will be more unique then.
I’m very happy until now! Thanks again.
Yes - this is possible. If there is a plant with only 2 words in the name, we need to decide what to do. In the following change I assume the missing character in the code would be “*”, but it could be nothing (i.e., “”).
Replace this line:
var thisCode = thisNameTokens.toString().split(" ")[0].substring(0, 1) + thisNameTokens.toString().split(" ")[1].substring(0, 1)
… with this one:
var thisCode = thisNameTokens.toString().split(" ")[0].substring(0, 1) + thisNameTokens.toString().split(" ")[1].substring(0, 1) + ((thisNameTokens.toString().split(" ")[2] == undefined) ? "*" : thisNameTokens.toString().split(" ")[2].substring(0, 1));
Resulting in this output -
