That part you wrote in explicit script, wont it work in on before or on after transform script ? - where we are setting subcategory value. But these on before qnd on after are basically used for validation ?
You said OnForeignInsert runs before reference record is created however when you are calling an event, there you are verifying user is available or not?