Very cool macro!
I couldn’t duplicate this so I don’t really know what you mean. But Keyboard Maestro is going to try to go through your fields and configure them itself, but exactly when that happens compared to when your code is executing is hard to know.
It calls a function KMInit() before filling in the fields, so that may be the place you want to do your work. I have added for the next version calls to KMWillShowWindow() and KMDidShowWindow() which may be useful in the future.