Personally, as the template is limited in its application I would put your logic via a view with a trigger to do the appropriate insert, i,e. personally I would put the intelligence on the database layer.
Others may see this differently.
Why don't you just put a unique index on the PK; then if the user tries to insert data for which there is a PK already it will fail.
If you want more complex logic then as Robert says, probably look to do it in the DB rather than OBIEE.
But, writeback is rudimentary at best and using it as a freeform data input tool where you need to worry about PKs etc, I would say is generally a bad idea.
Try have the procedure in the DB and call in the writeback template with parameters like below.
Thanks guys for your guidance