============
set_order_by
============

.. py:method:: set_order_by(self, lst=None, *fields)

**domain**: server

**language**: python

**class** :doc:`Item class </refs/server/item_api>`

Description
===========

Use the ``set_order_by`` method to define and store internally the ``order_by``
parameter that will be used by the 
:doc:`open <m_open>` 
method, when its own ``order_by`` parameter is not specified. The 
:doc:`open <m_open>` 
method clears internally stored parameter value. 

Parameters
==========

You can specify the fields as a list, the way the 
:doc:`set_order_by </refs/client/item/m_set_order_by>`
method on the client does or as non-keyworded arguments.

If there is a sign '-' before a field name, then on this field records will be 
sorted in decreasing order.

Example
=======

The result of the execution of following code snippets will be the same:

.. code-block:: py

    item.open(order_by=['customer', '-invoicedate'])

.. code-block:: py

    item.set_order_by('customer', '-invoicedate')
    item.open();

.. code-block:: py

    item.set_order_by(['customer', '-invoicedate'])
    item.open();
    
See also
========

:doc:`Dataset </programming/data/dataset>`

:doc:`open <m_open>`