Getting the ID of an inserted record

Getting the ID of an inserted record

I'm inserting a record in Deluge using

insert into Contracts
[
 Added_User = zoho.loginuser
 Engagement = input.ID
 Instigated_By = "Other"
]

What is the best way to get the ID of the inserted record?

I've tried changing the insert command to

rec = insert into Contract
[ .... etc. ]

but that fails on saving

I've also tried:

rec =  Contracts  Engagement == input.ID]
and
for each rec in  Contracts  Engagement == input.ID] {  }

both of which don't return an ID.

In the end, this seems to work:

for each rec in Contracts  [Engagement == input.ID]
{
    recid = rec.ID;
}

with recid being what I want (I think) - but that seems a bit laborious.

Is there a cleaner way?

Thanks

Alex