# Refresh View

If there is a view of connected records, Knack does not currently refresh the view of connected records. To work around this, we can implement this custom code so the connected view is also updated as well.

Original Post: [https://forums.knack.com/t/refreshing-a-details-view-on-form-submit-record-delete/18301](https://forums.knack.com/t/refreshing-a-details-view-on-form-submit-record-delete/18301)

Knack API Documentation for Record events: [https://docs.knack.com/reference/records-events](https://docs.knack.com/reference/records-events)

The original post also includes a GIF of the code in action as well.

### Some Example Use Cases

* Refreshing an Attachments table connected to a parent record form adding or deleting
* Refreshing a Invoice Grid Table connected to adding/deleting an invoice line item form
* Refreshing a Details View with connected records when a connected record is added or deleted

Keep in mind that for connected records, if you delete the parent record the connected record will no longer show up in the view but will be an orphaned record since Knack does not do cascading deletions.

### The Triggers

Modify line 14 below depending on what you wish to trigger the review refresh by

* `'knack-form-submit.view_XXX'` for form submit.
* `'knack-record-create.view_XXX'` for record create.
* `'knack-record-update.view_XXX'` for record update.
* `'knack-cell-update.view_XXX'` for record update through an inline edit in a table view
* `'knack-record-delete.view_XXX'` for record delete

### The JS

Copy/Paste the JS below and replace `view_XXX` and `view_YYY` in line 14-15.

* `view_XXX` is the view used for submitting a form on `knack-form-submit.view_XXX`
* `view_YYY` is the view that is being refreshed

{% code lineNumbers="true" %}
```javascript
/****************************************/
/*** Refresh View on Submit/Delete  ***/
/****************************************/
// A function to refresh a specified view
function refreshView(viewKey) {
  Knack.views[viewKey].model.fetch();
  setTimeout(() => {
    Knack.views[viewKey].render();
    Knack.views[viewKey].postRender();
  }, 2000);
}

// If record is submitted through form
$(document).on('knack-form-submit.view_XXX', function (event, view, data) {
  refreshView('view_YYY'); // the view being refreshed
});
```
{% endcode %}

