Introduction: In this document, I would discuss the generation of a sequence number which should be unique per message id and should increment by 1 per message. So, when the first time the message is processed, 1 should be populated in a certain field, second time 2, third time 3 & so on. However, if a failed message is reprocessed & mapping is executed again, then the sequence must not increase as the sequence number is already generated for that message ID. In order to achieve this, a Java mapping has been written, which has two methods for writing two properties file in PI application server. One of the files would have properties of message ID & the other would have properties of a unique identifier for that Interface.
As shown below, the Java mapping for sequence generation has been added as an imported archive. The code of this Java mapping can be found in the attachments section.
The below UDF’s are written for generating PI message ID, for message ID’s unique occurrence & for sequence number generation according to the PI message ID. Obviously the logic of generating PI Message ID occurrence, PI Message ID & the Sequence number generation could have been combined into a single code, but I kept them separate for the sake of simplicity.
I. For generating the PI Message ID:
II. For generating the occurrence of a particular message ID:
III. For generating the sequence for the message ID
The three UDF’s are used in mapping as shown below:
The constant value 6 denotes the range of the sequence i.e a range 3 would denote 1-999, after which the sequence restarts from the initial value i.e 1.
1. With message ID 54cbbe36-fd16-11e3-cd1f-00000656bfa2:
2. With message ID f11f1d56-fd15-11e3-ab1b-00000656bfa2:
3. With message ID 240c36dd-fd14-11e3-b28a-00000656bfa2:
4. With message ID as(Duplicate Message ID to test reprocessed message) f11f1d56-fd15-11e3-ab1b-00000656bfa2
Thus, when a duplicate message ID is tested, the sequence number is not increased. It happens because for each message ID, the below properties file is written in PI along with the properties file for the unique identifer. Notice the value of the message ID property which was processed twice has become 2, while the other message ID’s have value as 1. The method getMsgIDSequence checks the occurrence of the PI message ID & increments it only if the occurrence is equal to 1. The unique identifer could be any hardcoded value. In my case, I have provided it as UniqueFileIdentifier as the second input to the UDF SequenceNumberRetrieve.
Also the value of the unique identifier has become 3 as shown below: