Aaron McCausland
05/15/2026, 2:12 PMCeligo AI
05/15/2026, 2:12 PMAI generated answer (using internal Slack threads):To copy item groups from one transaction to another in SuiteScript, you need to iterate over the lines of the source transaction and recreate them in the target transaction. This process involves handling the item groups and their components separately. Here is a simplified version of the process: 1. Loop through each line of the source transaction. 2. Check if the current line is an item group. If it is, set a flag to indicate that you are within an item group. 3. If you are within an item group, copy the line details to the target transaction but do not commit the line yet. Keep track of the total amount for the item group. 4. If the current line is the end of an item group, set the total amount for the item group in the target transaction and commit the line. Then reset the item group flag and the total amount. 5. If the current line is not part of an item group, copy the line details to the target transaction and commit the line. Here is a code sample that demonstrates this process:
javascript
for (let i = 0; i < sourceTransaction.getLineCount('item'); i++) {
if (isItemGroup) {
targetTransaction.selectLine({sublistId: 'item', line: i});
targetTransaction.setCurrentSublistValue('item', 'quantity', sourceTransaction.getSublistValue('item', 'quantity', i));
targetTransaction.setCurrentSublistValue('item', 'rate', sourceTransaction.getSublistValue('item', 'rate', i));
targetTransaction.setCurrentSublistValue('item', 'amount', sourceTransaction.getSublistValue('item', 'amount', i));
targetTransaction.setCurrentSublistValue('item', 'price', sourceTransaction.getSublistValue('item', 'price', i));
itemGroupTotal += targetTransaction.setCurrentSublistValue('item', 'amount', sourceTransaction.getSublistValue('item', 'amount', i));
}
if (sourceTransaction.getSublistValue('item', 'itemtype', i) == 'EndGroup') {
targetTransaction.setCurrentSublistValue('item', 'amount', itemGroupTotal);
isItemGroup = false;
continue;
}
if (!isItemGroup && sourceTransaction.getSublistValue('item', 'itemtype', i) != 'EndGroup') {
targetTransaction.selectNewLine({sublistId: 'item'});
targetTransaction.setCurrentSublistValue('item', 'item', sourceTransaction.getSublistValue('item', 'item', i));
targetTransaction.setCurrentSublistValue('item', 'quantity', sourceTransaction.getSublistValue('item', 'quantity', i));
if (targetTransaction.getCurrentSublistValue('item', 'itemtype') == "Group") {
isItemGroup = true;
targetTransaction.setCurrentSublistValue('item', 'amount', 123);
targetTransaction.commitLine({sublistId: 'item'});
continue;
}
targetTransaction.setCurrentSublistValue('item', 'rate', sourceTransaction.getSublistValue('item', 'rate', i));
targetTransaction.setCurrentSublistValue('item', 'amount', sourceTransaction.getSublistValue('item', 'amount', i));
targetTransaction.commitLine({sublistId: 'item'});
}
}
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
05/15/2026, 2:13 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833923399
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826721251
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816162169
Celigo AI
05/15/2026, 2:13 PM