PXAccumulator: Implementation of a Custom PXAccumulator Attribute

When you define a custom accumulator attribute, you typically implement the members that are described in the following sections.

Tip:

Attribute Constructor

By setting the value of the _SingleRecord field in the constructor to true, you specify that the system should use single-record update mode. In this mode, the attribute updates the data record independently from the existing data records and does not add any restrictions to future data records. In single-record update mode, the framework generates a specific SQL statement that updates an independent record. By default, single-record mode is not used.

PrepareInsert() Method

In the overridden PrepareInsert() method, you first have to invoke the base PrepareInsert() method to initialize the collection of columns. If the base PrepareInsert() method returns true, the collection of columns is initialized. Then in the overridden method, you can set restrictions and update policies for specific columns. For details about policies, see the description of the PXDataFieldAssign.AssignBehavior enumeration.

In the PrepareInsert() method, the columns are represented by an object of the PXAccumulatorCollection class. To update a value or to set a restriction for a column, you invoke the needed generic method of the columns collection. You can use the following methods in single-record mode (that is, when _SingleRecord = true is specified in the attribute constructor):

  • columns.Update(): Sets the update policy for the field.
  • columns.Restrict(): Sets the value restriction for the column. The restriction triggers the PXLockViolationException exception, which you should handle in the overridden PersistInserted() method of the attribute.

PersistInserted() Method

If you set any restrictions, you have to override the PersistInserted() method. For details, see PXAccumulator: Implementation of an Update with Restrictions.