As we have talked on Discord, you cannot layer_tilemap_get_id on dynamically created layers.
You will have to make a small script like
/// layer_tilemap_get_id_fixed(layer) var els = layer_get_all_elements(argument0); var n = array_length_1d(els); for (var i = 0; i < n; i++) { var el = els[i]; if (layer_get_element_type(el) == layerelementtype_tilemap) { return el; } } return -1;