Kinda crazy request here, but is there any script ...
# suitescript
s
Kinda crazy request here, but is there any script functionality that defaults to a certain field selected? So you know how you create a Bill, for example and the Vendor is automatically what the form chooses to select - what if we wanted it to be the date? This would help a lot - thanks so much!
You know, I think I may have answered my own question... What if we write a script that populates the date field? Maybe that would automatically move the cursor over there? Gonna play around with that idea!
s
It may or may not, but you could always try the following in a client script, though it may break if NetSuite ever changes how they generate the html inputs:
document.getElementById('trandate').focus();
I am not sure of there is a way to set the focus using SuiteScript api methods.
🔥 1
s
Scott comin' in with the HEAT! Nice! Super appreciative of the input.
s
it's always recommended to avoid direct DOM access if possible, but sometimes NetSuite doesn't provide a supported method. As long as someone is willing to maintain it in the future if it breaks, it's usually okay.
s
Ah gotcha.
Yeah, I'll likely have some type of process in place to disable the deployment if something breaks. I mean, it's such a friggin minor feature that it's super not worth it.
Thanks Scott!
s
best of luck!
m
If you are touching the DOM make sure your script fails gracefully if it changes / any errors E.g. change
document.getElementById('trandate').focus()
to
var elem = document.getElementById('trandate'); if (elem) { elem.focus(); }
and you can always wrap the whole thing in a
try/catch
etc..
s
Brilliant ideas, gentlemen! Thank both of you so much!
Dang it's so friggin' close. I actually don't think it's possible. Like I can't find the proper entry point for it. If I choose pageInit, the cursor goes to Date for a millisecond and immediately goes to Vendor. If I go for validateField or something, it will ONLY redirect to the date field. DANG IT!
m
Try adding it with a delay in pageInit.
window.setTimeout(function() { var elem = document.getElementById('trandate'); if (elem) { elem.focus(); } }, 1000);
(update the 1000 to the delay in milliseconds that works best