Using data from one or more tables, you can insert into a completely separate Header Detail structure.
To insert into a Header/Detail structure, you must create two temp tables in the logic block. One for the header table of the H/D structure and one for the detail table of the H/D structure. Throughout the logic block, you can insert into the temp tables and then use them as the Header table and Detail table when you want to insert into the Header/Detail structure.
Example
The most common use case for this logic block pattern is inserting into the GeneralLedgerTransactions Header detail structure when writing a journal entry. Cash transfers, supplier invoices, expense reports, payments, donation receipts, and other various application write journal entries.
Accountants use the Cash Transfer application to transfer money from one account to another account, and the resulting transaction must be recorded as a journal entry. After the cash transfer workflow status changes to Ready to Post, the WriteCashTransferGLRecord logic block runs, which takes the information in the cash transfer record and writes a corresponding journal entry. When the logic block runs successfully, the cash transfer status changes to Posted to GL. When the logic block errors, the cash transfer workflow status changes to Error.
First, the logic block creates two temp tables: one that matches the structure for the GeneralLedgerHeader table, which is the header table for the GeneralLedgerTransactions Header/Detail table, and one that matches the structure for GeneralLedgerDetail table, which is the detail table for the GeneralLedgerTransactions Header/Detail table.
When creating the temp table for the header, the Allow Multiple Entries check box must be cleared. When creating the temp table for the detail, Allow Multiple Entries check box must be selected. This is because one Header/Detail record can have one header and multiple details, but it cannot have multiple headers.
Next, the GLHeader temp table is inserted into once and the GLDetail temp table is inserted into twice because the debits and credits in the detail records must be equal to write a journal entry.
Like inserting records into the detail of a Header/Detail application without saving the detail records to the database, the name of the inserts into the temp tables must be the same as the temp table name. If the names are not the same, the insert does not work.
After records have been inserted into the header and detail temp tables, use the Save HD action to insert into the GeneralLedgerTransactions table. Unlike the inserts to the temp tables, the name of the Save HD action doesn't have to match the name of the Header/Detail table. The GLHeader temp table is used as the header table and the GLDetail temp table is used as the detail table.
In this example, the WriteGLTransaction logic block is called to do the insert into the GeneralLedgerTransactions table. WriteGLTransaction is the one source to write entries to the GeneralLedgerTransaction table. In the Call a Logic Block action, the GLHeader temp table is used as the header table and the GLDetail table is used as the detail table.