Yeah, you definitely can't insert data into a table inside a function.
Let me ask this - are you simply looking to return an integer that represents the newly-inserted identity value? After reading your posts again, maybe I don't quite understand what the objective is.