Creation of a simple outbound message
For the sake of explanation, this manual will implement a fake message "Tutorial Outbound Integration". We will abbreviate this in code as "TUTOutIntegration".
Enum value
Each integration is uniquely identified by a value in the enum SMRIFMessageTypes. In order to create a new message, we have to create a new value in the enum. In this case, we add an enum value TUTOutIntegration with the label "Tutorial Outbound Integration".
Staging data
All staging tables are centered around the framework table SMRIFMessage. The staging tables form a hierarchical tree structure below this generic message table.
It is important that each staging table
- has the save data per company property set to no.
- is related to a parent table, with a cascade delete action.
- has an index on the parent relation field.
For the sake of this demo, we can create two staging tables:
-
TUTOutIntegrationHeader
- Has a field message that relates to the SMRIFMessageTable.RecId field.
- Has integration specific fields HeaderField1, HeaderField2, ...
-
TUTOutIntegrationLine
- Has a field Header that relates to the TUTOutIntegrationHeader.RecId field.
- Has integration specific fields LineField1, LineField2, ...
The appropriate incoming json file that matches this staging table structure can be found here.
Type class
This class relates all code and tables involved in this integration together.
We can create this class by extending from the framework class SMRIFAbstractMessageOutType. The name for this class in our case would be TUTOutIntegrationType. This class should be attributed with the SMRIFMessageTypeAttribute corresponding to the enum value we created earlier.
At the very basis, the class declaration of our type class should now look like this:
[SMRIFMessageTypeAttribute(SMRIFMessageTypes::TUTOutIntegration)]
public class TUTOutIntegrationType extends SMRIFAbstractMessageOutType
{
}
This class should implement a couple of abstract methods from the superclass it extends.
detailMenuItem
This method should return a display menu item that opens a details form. This new-to-be-created details form should have the SMRIFMessage table as a root datasource. It should offer a detailed view of one instance of your incoming message. All fields in every staging table should be visible on this form. Consider if you want fields to be editable on this form. On one hand, this recudes tracability, while on the other hand, it improves error handling.
tableRelationsMap
This method defines the hierarchical structure of our staging data. It does this by building and returning a map that maps strings to table relations. These string match 1:1 with what is in the outbound json file, while the table relations match with the relations between the staging tables. In order to represent a table relation, we use the framework class SMRIFTableField.
In our case, consider the following map, to which indentation has been added for clarity:
Map map = new Map(Types::String, Types::Class);
map.insert(
SMRIFConstants::Content, // The string 'content' as found in the json file
SMRIFTableField::construct( // A table relation
tableNum(TUTOutIntegrationHeader), // The table 'TUTOutIntegrationHeader' uses ....
fieldNum(TUTOutIntegrationHeader, Message), // .... the field 'Message' to relate to ....
tableNum(SMRIFMessage))); // .... the table 'SMRIFMessage'.
map.insert(
tableStr(TUTOutIntegrationLine), // The string 'TUTOutIntegrationLine' as found in the json file
SMRIFTableField::construct( // A table relation
tableNum(TUTOutIntegrationLine), // The table 'TUTOutIntegrationLine' uses ....
fieldNum(TUTOutIntegrationLine, Header), // .... the field 'Header' to relate to ....
tableNum(TUTInIntegrationHeader))); // .... the table 'TUTInIntegrationHeader'.
Creation class
This class is responsible for the creation of data in our staging tables. It should extend from the framework class SMRIFCreateOutMessage.
At the very basis, the class declaration should look like this:
public class TUTCreateOutIntegration extends SMRIFCreateOutMessage
{
}
This class should implement a couple of abstract methods from the superclass it extends. There should also be a static create method to trigger this class.
create
This method instantiates an object of this class and runs it. The run method will tie in to the superclass implementation, and will trigger any additional processing that is needed.
It should look like this:
public static void create(SomeTable _someTable)
{
new TUTCreateOutIntegration(_someTable).run();
}
completeMessageProperties
This method fills properties on the SMRIFMessage record. This code could look like this, depending on your usecase:
protected void completeMessageProperties()
{
message.Type = SMRIFMessageTypes::TUTOutIntegration; // Mandatory!
message.Reference = someRecord.SomeUsefulIdentifyingField; // Allows for easily searching the logs
message.ProcessType = SMRIFProcessTypes::Synchronous; // Synchronous: Send now (interactive, wait for response). Asynchronous: Code execution resumes, message is sent in batch.
message.AXRecordId = someRecord.RecId; // Allows for easily searching the logs
}
createContent
This method inserts records in the staging tables based on the data that was passed to this class.