Marygolds3
06/22/2021, 9:34 PMbattk
06/22/2021, 9:35 PMKevin
06/22/2021, 9:35 PMKevin
06/22/2021, 9:36 PMMarygolds3
06/22/2021, 9:36 PMMarygolds3
06/22/2021, 9:37 PMdefine(['N/search', 'N/record', 'N/log' , 'N/runtime', 'N/format'],
function(search, record, log, runtime, format) {
function afterSubmit(scriptContext) {
var scriptType = scriptContext.type;
var newInvoice = scriptContext.newRecord;
var exContext = runtime.executionContext;
var recordType = newInvoice.type;
var inv_Id = newInvoice.id;
try{
if((exContext == runtime.ContextType.WEBSERVICES || exContext == runtime.ContextType.USER_INTERFACE) && (scriptType == 'create' || scriptType == 'edit') && (recordType == 'invoice')){
log.debug('BS recordType is '+recordType, 'inv_Id is '+inv_Id);
var newInvoice = record.load({
type: record.Type.INVOICE,
id: inv_Id,
isDynamic: true,
});
var itemLines = newInvoice.getLineCount({
sublistId: 'item'
});
log.debug('itemLines is', itemLines);
if(itemLines > 0){
for( var itemLinesLen = 0 ; itemLinesLen < itemLines ; itemLinesLen++ ){
var curItemName = newInvoice.getSublistText({
sublistId: 'item',
fieldId: 'item',
line: itemLinesLen
});
log.debug('curItemName is', curItemName);
var item = newInvoice.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: itemLinesLen
});
var rate = newInvoice.getSublistValue({
sublistId: 'item',
fieldId: 'rate',
line: itemLinesLen
});
var quantity = newInvoice.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: itemLinesLen
});
if(itemLines == 1){
var previousItemDescription = newInvoice.getSublistValue({
sublistId: 'item',
fieldId: 'description',
line: itemLinesLen
});
log.debug('previousItemDescription is', previousItemDescription);
var lineNum = newInvoice.selectNewLine({
sublistId: 'item'
});
newInvoice.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: item
});
newInvoice.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'pricelist',
value: -1
});
newInvoice.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: rate*-1
});
newInvoice.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: quantity
});
newInvoice.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'description',
value: 'Discount-' + curItemName
});
newInvoice.commitLine({
sublistId: 'item'
});
}
if(item == 57375){
log.debug('item is ', item);
var lineNum1 = newInvoice.selectLine({
sublistId: 'item',
line: 2
});
newInvoice.setCurrentSublistText({
sublistId: 'item',
fieldId: 'description',
value: 'Discount-' + curItemName
});
newInvoice.commitLine({
sublistId: 'item'
});
}
newInvoice.save();
}
}
}
}
catch(afterSubmitError) {
log.error('afterSubmitError is ', afterSubmitError.message);
}
}
return {
afterSubmit: afterSubmit
};
});Marygolds3
06/22/2021, 9:37 PMSandii
06/22/2021, 9:40 PMSandii
06/22/2021, 9:41 PMline: 2
inside a conditional checking what the itemId isMarygolds3
06/22/2021, 9:45 PMMarygolds3
06/22/2021, 9:45 PMMarygolds3
06/22/2021, 10:09 PMMarygolds3
06/22/2021, 10:09 PMMarygolds3
06/22/2021, 10:09 PMbattk
06/22/2021, 10:20 PMbattk
06/22/2021, 10:22 PMMarygolds3
06/22/2021, 10:27 PMMarygolds3
06/22/2021, 10:27 PMMarygolds3
06/22/2021, 10:27 PMMarygolds3
06/22/2021, 10:27 PMMarygolds3
06/22/2021, 10:27 PMMarygolds3
06/22/2021, 10:28 PMMarygolds3
06/22/2021, 10:28 PMbattk
06/22/2021, 10:29 PMMarygolds3
06/22/2021, 10:29 PMMarygolds3
06/22/2021, 10:29 PMMarygolds3
06/22/2021, 10:29 PMbattk
06/22/2021, 10:29 PMMarygolds3
06/22/2021, 10:30 PMbattk
06/22/2021, 10:30 PMMarygolds3
06/22/2021, 10:30 PMMarygolds3
06/22/2021, 10:30 PMMarygolds3
06/22/2021, 10:30 PMMarygolds3
06/22/2021, 10:31 PMMarygolds3
06/22/2021, 10:31 PMbattk
06/22/2021, 10:32 PMbattk
06/22/2021, 10:32 PM