===============================
How to prohibit changing record
===============================

Let's assume that we have an item with a boolean field "posted", and if the 
value of the field is true, we must prohibit changing or deleting the record.

We can do this by writing the
:doc:`on_after_scroll </refs/client/item/on_after_scroll>` 
event handler and using 
:doc:`permissions </refs/client/item/at_permissions>` property:

.. code-block:: js

  function on_after_scroll(item) {
      if (item.rec_count) {
          item.permissions.can_edit = !item.posted.value;
          item.permissions.can_delete = !item.posted.value;
          if (item.view_form) {
              item.view_form.find("#delete-btn").prop("disabled", item.posted.value);    
          }
      }
  }
  
In this event handler we check the value of the "posted" field and set the 
:doc:`permissions </refs/client/item/at_permissions>` property attributes to true.

We can also write the 
:doc:`on_apply </refs/server/item/on_apply>`
event handler in the server module of the item:

.. code-block:: py

  def on_apply(item, delta, params, connection): 
    for d in delta:
        if d.posted.old_value:
            raise Exception('Document posted. No change allowed')
