How to store template_id that new event is derived from
This is the reverse of what you're trying to do but might have the intended result:

Instead of populating the custom field after event creation, how about adding the custom field to your event template and populating it there?