How to stop Kintone from saving duplicate records in the Create Record page?

I want to prevent users from saving duplicate company records in the database.

So in the app.record.create.submit event handler, I call checkDuplicate(record) to check to see if the company record already exists.
The checkDuplicate(record) is a function that calls a kintone.proxy().

The kintone.proxy() is an asynchronous operation.

The problem is the event handler app.record.create.submit finishes before kintone.proxy() finishes, and the duplicate record is saved.

How to stop the user from saving a duplicate company record?

This event is triggered when the SAVE button is clicked on the record create page.

kintone.events.on("app.record.create.submit", function (event) {
  var record = event.record;
  checkDuplicate(record);
  return event;
});

Before we look deeper into this, …

Perhaps the Prohibit Duplicate Values setting, a native feature available in many fields, might meet your needs.