Document sequences





Overview

The document sequence mechanism ensures that interrelated documents are posted in the correct order. The main idea of this mechanism is that a document posting procedure can depend on certain data stored in the infobase. To be exact, the document posting procedure depends on the data values that were stored in the infobase at the time when the document was registered in the infobase. If this data is changed after document posting, the document must be reposted in order to update its register records. For example, if a document reads item prices from an information register, a price change invalidates the register records of this document and the document must be reposted to correct them.

This mechanism uses the following algoritm. When a document is written, it is registered in a document sequence. It means that the document posting procedure is based on certain data stored in the infobase, and the result of document posting depends on the data values that were stored at certain time. At the end of document posting 1C:Enterprise checks all of the sequences where the document is registered. For each sequence, 1C:Enteprise checks whether all of the documents registered in the sequence before this document were posted in the correct order. If they were posted in the correct order, the document posting is considered to be correct. If they were not posted in the correct order, the document posting is considered to be incorrect and the document must be reposted.

When the data that affects document posting changes, 1C:Enteprise defines which document sequences depend on this data. All of the documents that are registered in these sequences after the data being changed was written get the "repost pending" flag.

Application users can learn which documents were posted correctly and which were not. They can get this data as the point in time, before which all documents are posted in the right sequence. All of the documents posted after this point in time are considered to be posted in an incorrect order. Knowing this, a user can decide to restore the correct order of document posting. This includes reposting all of the documents that belong to the sequence and were posted earlier.

Implementation details

When developing an application, a developer describes which documents are included in a sequence and which data affects their posting. All this data is defined in Sequence metadata object. A developer specifies a list of documents that form a sequence and a list of registers whose data affects document posting. Note that the platform monitors the changes of data that affect document sequences only in accumulation, calculation, accounting, and information registers.

A document sequence can have dimensions. You can use dimensions to split document sequences into smaller parts. For example, if a document posting procedure involves item prices stored in an information register, changing a single item price initiates the reposting of all documents of that kind, even those that do not include that specific item. To solve the problem, you can add the Item dimension to a document sequence. When a document is registered in a document sequence, its registration record includes the items affected by the document. When 1C:Enteprise restores a document sequence, it can determine which items were changed and, consequently, which documents are to be reposted.

Document registration in a sequence can be performed automatically. First, a developer must set a mapping between document attributes and document sequence dimensions. If one or several attributes of a tabular section are included in the mapping, a document is registered in a sequence multiple times, one for each unique combination of attribute values. If attributes of different tabular sections are mapped to sequence dimensions, the number of registrations is the number of unique combinations of these tabular section attribute values. If all tabular sections have unique combinations of attribute values in all the lines, the number of registrations is N1*N2...*Ni, where Ni is the number of lines in a tabular section.

To automatically track data changes broken down by document sequence dimensions, specify a mapping between register dimensions and attributes and document sequence dimensions. Note that documents are not automatically registered in sequences upon creating a document sequence or adding a document type. To register documents in a sequence, you have to write them or write a data processor that registers documents in a sequence.

The document sequence mechanism uses two entities: document registration in a sequence and sequence boundary. 1C:Enterprise сreates a data table for each entity. A registration table stores the details of document registration in a sequence. Both tables can be accessed using 1C:Enterprise query language.

A registration table has the following fields: period, recorder, and sequence dimensions. A document registration table contains records with dimension value combinations that are unique for a single recorder. In other words, a registration table stores a single record for a specific combination of dimension values within a single recorder, still it can store multiple records with the same set of attribute values for different recorders. You can access the table data through the record set that describes document registrations in a sequence. A document object has a collection of record sets that describe its registration in document sequences. 1C:Enterprise uses the record sets from this collection to register documents in sequences when the documents are being written. Note that when the posting is cleared, the registration in document sequences is not cleared. However, an unposted document does not participate in sequence restoration. In all other respects, operations with records sets that describe document registrations in sequences are similar to operations with any other register record sets.

A sequence boundary indicates a point in time (boundary) after which the documents are posted incorrectly. The boundary table structure is similar to the registration table structure, still its content and meaning are different. In contrast to registration tables, boundary tables contain only records that have unique dimension value sets. In other words, there is only one record for a specific combination of dimension values. A period and a recorder specify the point in time of a boundary by specific dimensions. The content of a sequence boundary table may be changed only through a document sequence manager object.

Document writing procedure:

Start a transaction

    Fill the record sets that describe document registration in a sequence

    Call predefined procedure BeforeWrite()

    Write the document

    Call predefined procedure OnWrite()

    Write document record sets that are changed but not yet recorded

        Check and move sequence boundaries to the point in time of these record sets (this action is performed in a record set, not in a document)

    Write record sets describing document registration in a sequence that are changed but not yet recorded

End a transaction

Document writing procedure with posting

Start a transaction

    Fill the record sets that describe document registration in a sequence

    Call predefined procedure BeforeWrite()

    Write the document

    Call predefined procedure OnWrite()

    Call predefined procedure Posting()

    Write document record sets that are changed but not yet recorded

        Check and move sequence boundaries to the point in time of these record sets (this action is performed in a record set, not in a document)

    Write record sets describing document registration in a sequence that are changed but not yet recorded

    Check and move sequence boundaries to the point in time of these record sets

End a transaction

Document writing procedure with posting cleared

Start a transaction

    Fill the record sets that describe document registration in a sequence

    Call predefined procedure BeforeWrite()

    Call predefined procedure UndoPosting()

    Delete record sets

        Check and move sequence boundaries to the point in time of these record sets (this action is performed in a record set, not in a document)

    Write a document

    Call predefined procedure OnWrite()

    Write record sets describing document registration in a sequence that are changed but not yet recorded

End a transaction

Note that the backward movement of a sequence boundary (boundary displacement) can only occur when register record sets are being written with boundaries that are greater (later) than the time of the record set. The forward movement of a sequence boundary (boundary restoration) can only occur when a document is being posted with boundaries that are less (earlier) than the document time, and only if there are no other documents belonging to that sequence between the sequence boundary and the document being posted (so that no documents need to be reposted). To sum it up, automatic boundary displacement can only occur when register data is changed, regardless of the origin of the record set that changes the data (it might or might not be generated by the document). A sequence is restored automatically only during document posting. Writing a document, registering a document in a sequence, or posting a document cannot displace a sequence boundary. Only a register change can displace a boundary.

Application developers can use 1C:Enterprise script methods to set boundaries to arbitrary points in time. They also can get current sequence boundaries, check whether a sequence boundary is displaced, check whether a document belongs to a sequence, and restore sequences.


Comments
0
Add comment