# How to ignore an event or wait for all events to complete?

**URL:** <https://forum.kintone.dev/t/how-to-ignore-an-event-or-wait-for-all-events-to-complete/539>\
**Category:** General\
**Tags:** event-handling\
**Created:** [August 11, 2022, 2:44am UTC](https://forum.kintone.dev/t/how-to-ignore-an-event-or-wait-for-all-events-to-complete/539 "2022-08-11T02:44:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuankiet116](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/tuankiet116/32/35_2.png) [@tuankiet116](https://forum.kintone.dev/u/tuankiet116)\
**Post date:** [August 11, 2022, 2:44am UTC](https://forum.kintone.dev/t/how-to-ignore-an-event-or-wait-for-all-events-to-complete/539/1 "2022-08-11T02:44:25Z")

</div>

Hi, I’m trying to set records into a table and I’m using event catch field on change of Kintone.

I want to check all fields when it changes in the table or be set from JavaScript is validated or not and in some cases when events is raised, some fields of table still have no value.

So I want to waiting when all fields in table have value and I’m trying to ignore event went it be set from javascript or wait for all events is done.

Any solutions?

```javascript
let eventChangesFieldTable = [
  `app.record.create.change.${codeNo}`,
  `app.record.create.change.${codeStaffNo}`,
  `app.record.create.change.${codeTable}`,
  `app.record.create.change.${codeQuantity}`,
  `app.record.create.change.${codePrice}`,
  `app.record.create.change.${codeStaffFurigana}`,
  `app.record.create.change.${codeName}`,
  `app.record.create.change.${codeCompany}`,
  `app.record.edit.change.${codeNo}`,
  `app.record.edit.change.${codeStaffNo}`,
  `app.record.edit.change.${codeTable}`,
  `app.record.edit.change.${codeQuantity}`,
  `app.record.edit.change.${codePrice}`,
  `app.record.edit.change.${codeName}`,
  `app.record.edit.change.${codeCompany}`,
]

kintone.events.on(eventChangesFieldTable, function (e) {
  console.log(e.type);
  if (isInvalid(e.record[codeTable])) {
    debugger
    return false;
  } else {
    let { dataTable, ids } = groupDataSelected(e.record);
    dataChoosed = dataTable;
    idSelected = ids;
  }
});

```

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/chris/32/44_2.png) [@Chris](https://forum.kintone.dev/u/Chris)\
**Post date:** [August 15, 2022, 5:37pm UTC](https://forum.kintone.dev/t/how-to-ignore-an-event-or-wait-for-all-events-to-complete/539/2 "2022-08-15T17:37:55Z")

</div>

Hello!

Using Promises or Async/Await to create an asynchronous process should resolve your issue.

> **[How to use promises - Learn web development | MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises)**
>
> Promises are the foundation of asynchronous programming in modern JavaScript. A promise is an object returned by an asynchronous function, which represents the current state of the operation. At the time the promise is returned to the caller, the...

> **[async function - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)**
>
> An async function is a function declared with the async keyword, and the await keyword is permitted within it. The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly...

The following is an example of obtaining three records and totaling their value upon saving a record:

**Promises Example:**

```javascript
kintone.events.on(['app.record.create.submit', 'app.record.edit.submit'], (event) => {
  
  return kintone.api('/k/v1/record', 'GET', params1)
    .then((resp1) => {
      event.record.Total.value += Number(resp1.record.Subtotal.value);
      // 2nd API Process
      return kintone.api('/k/v1/record', 'GET', params2);
      // Using .then() to wait for the process
    }).then((resp2) => {
      event.record.Total.value += Number(resp2.record.Subtotal.value);
      // 3rd AP Process
      return kintone.api('/k/v1/record', 'GET', params3);
      // Using .then() to wait for the process
    }).then((resp3) => {
      event.record.Total.value += Number(resp3.record.Subtotal.value);
      return event;
    }).catch((e) => {
      // In case of API error
      alert(e.message);
      return event;
    });
});

```

\*You can use Promise.all() too

**async/await Example:**

```javascript
kintone.events.on(['app.record.create.submit', 'app.record.edit.submit'], async (event) => {
    try {
      const resp1 = await kintone.api('/k/v1/record', 'GET', params1);
      const resp2 = await kintone.api('/k/v1/record', 'GET', params2); //
      const resp3 = await kintone.api('/k/v1/record', 'GET', params3); //

      event.record.Total.value = Number(resp1.record.Subtotal.value) + Number(resp2.record.Subtotal.value) + Number(resp3.record.Subtotal.value);
      return event;
    } catch(e) {
      // In case of API error
      alert(e.message);
      return event;
    }
  });

```

I hope this helps.

---

<div class="post-metadata">

**Author:** ![tuankiet116](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/tuankiet116/32/35_2.png) [@tuankiet116](https://forum.kintone.dev/u/tuankiet116)\
**Post date:** [August 16, 2022, 3:47am UTC](https://forum.kintone.dev/t/how-to-ignore-an-event-or-wait-for-all-events-to-complete/539/3 "2022-08-16T03:47:22Z")

</div>

Thank you I’ll try your solution!
