==============
on_open_events
==============

When the ``open`` method of the item is called 
on the :doc:`client </refs/client/item/m_open>` or the 
:doc:`server </refs/server/item/m_open>`, the server application
executes the following code:

.. code-block:: py

  result = None
  if self.task.on_open:
      result = self.task.on_open(self, params)
  if result is None and self.on_open:
      result = self.on_open(self, params)
  if result is None:
      result = self.execute_open(params)

It checks if the task has an ``on_open`` event handler. If the ``on_open`` 
event handler is declared in the task server module, it is executed.

If the ``on_open`` event handler of the task is not declared or the result 
of the event handler returns ``None``, the method checks whether the item has an 
:doc:`on_open </refs/server/item/on_open>`
event handler. If it is declared in the item server module, it is executed.

If the result returned by the item event handler is ``None``, the 
``execute_open`` method of the item is called that generates SQL query,
execute it and returns the result

Example
=======

:doc:`Here is an example how on_open can be used </how_to/how_to_multitenancy>`
