This is incomplete explanation [member=ceroberoz].
The first part getting the foreign key can be done by using the callback_after_insert after the user saves (inserts) a record.
But you haven't defined what you want to do with this!
Table B doesn't get by magic the foreign key from the newly inserted record.
If you mean after a new insert on table A when the user inserts a new record on table B then this newly inserted id (from table A) to be used as the id of the foreign key of table's B aid, then this is a completely different issue!!!
You need to strictly specify how the aid is getting populated... just imagine the very possible scenario where two users save around the same time two news records on table A. Which value will you store on your aid of table B?