Mike Casey
11/18/2024, 8:11 PMCeligo AI
11/18/2024, 8:11 PMAI generated answer (using internal Slack threads):Based on the conversations, it seems like you are trying to add a discount line item for each inventory item in a sales order using client-side SuiteScript. Here's a sample script that might help you:
javascript
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/record', 'N/currentRecord'], function(record, currentRecord) {
function lineInit(scriptContext) {
var currentRec = scriptContext.currentRecord;
var sublistName = scriptContext.sublistId;
if (sublistName === 'item') {
var itemType = currentRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'itemtype'
});
if (itemType === 'InvtPart') {
var itemRate = currentRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate'
});
var discountRate = itemRate * 0.10; // 10% discount
currentRec.selectNewLine({
sublistId: 'item'
});
currentRec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 'DISCOUNT_ITEM_ID' // replace with your discount item internal id
});
currentRec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: discountRate
});
currentRec.commitLine({
sublistId: 'item'
});
}
}
}
return {
lineInit: lineInit
};
});
This script listens to the lineInit
event, which is triggered whenever a line item is initialized. It checks if the line item is an inventory item (InvtPart
). If it is, it calculates a 10% discount based on the item's rate, then adds a new line with the discount item and the calculated discount rate.
Please replace 'DISCOUNT_ITEM_ID'
with the internal ID of your discount 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
11/18/2024, 8:12 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851885676
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830416501
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826088488
Celigo AI
11/18/2024, 8:12 PM