A few things,
If you are just trying to have an incremental Key take a look at the existing Epicor Solution to accomplish this here’s a walk through
Further more, if you want to maintain your own (for some reason) then the approach should be a BPM and not UI. Simple put a Post Processing BPM on GetaNewUD11 that does what your SQL query does that is find the Max of whatever and then assign that to your Key Field.