Update and insert into form at the same time

Update and insert into form at the same time

I need to write a script so when importing records into a form, the existing records are updated, while the new records are inserted. 

How can I start writing such a script? Thanks!