Flags and Status

The status of a document changes two ways:

(1) User deliberately sets the status by setting the value of a field, or

(2) Some other values are changed or transaction created that alters the status.

In cases where (1) is applicable, it's customary to have a flag field (say, xflag or xflagtrn) in the table set to an appropriate value (say, 'Authorized'). Where (2) is applicable, you derive the value by checking a related transaction or a computed value. This derived field is usually called a status (say, xstatuspor).

Guidelines

Here are some guidelines that you should follow to ensure that you are doing it right.

(1) A flag should only be defined in a table and never as a computed value in a SQL statement or a view.

(2) A status should only be defined as a computed value in a SQL statement or a view and never as a field in a table.

(3) Use flags only when no logical way of deriving a value for it exists. For instance, to check whether a document is posted to GL, you should check for existence of a GL records with the same document, instead of simply updating a flag to 'Posted'.

(4) Flags are to be updated with a single user action without effect on anything else in the system. For instance, if you wanted to update a flag to the value 'Delivered', the process should do only that function and nothing else. If it does otherwise, most probably you shouldn't be using a flag. Say, you set the value of Qty Delivered to 30 and at the same time set the value of the flag to 'Delivered'. Obviously, you shouldn't be using the flag at all. Assuming you have a Qty Ordered field, you should be able to derive the status by comparing the two quantities. A 0 value for Qty Delivered will mean nothing has been delivered. If it's greater than 0 and less than Qty Ordered, the status should be 'Partially Delivered'. If they are same then 'Delivered' or else 'Excess-Delivered'. Even if the field Qty Ordered didn't exist, you could derive the status solely based on the value of Qty Delivered. There is no need for the flag field. What would happen if after you updated the flag to 'Delivered', some other method or page changed the Qty Delivered to 0?

Click on Syntax to learn how to use and change this wiki.