Samantha Solomon
03/12/2024, 8:33 PMSamantha Solomon
03/12/2024, 8:33 PM/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record'],
function (search, record) {
function execute(context) {
try {
var wsiInvoicesSearch = search.load({id: 'customsearch_wsi_invoices_in_error_test'})
var wsiInvoicesSearchResults = wsiInvoicesSearch.run()
wsiInvoicesSearchResults.each(function(invoice){
var invoiceId = invoice.id
var loadedInvoice = record.load({
type: record.Type.INVOICE,
id: invoiceId,
isDynamic: true
})
loadedInvoice.setValue({
fieldId: 'automaticallyapplypromotions',
value: false
})
var promotionsLineCount = loadedInvoice.getLineCount({sublistId: 'promotions'})
for (var i = promotionsLineCount; i > 0; i--) {
log.debug("promo line",
loadedInvoice.selectLine({
sublistId: 'promotions',
line: i
}))
loadedInvoice.removeLine({
sublistId: 'promotions',
line: i
})
}
var itemLineCount = loadedInvoice.getLineCount({sublistId: 'item'})
for (var i = 0; i < itemLineCount; i++) {
loadedInvoice.selectLine({
sublistId: 'item',
line: i
})
var itemType = loadedInvoice.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'itemtype'
})
if (itemType != 'Discount') {
var itemDisplay = loadedInvoice.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'item_display'
})
var tpPrice = loadedInvoice.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_sps_purchaseprice'
})
loadedInvoice.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
line: i,
value: tpPrice
})
loadedInvoice.commitLine({
sublistId: 'item',
line: i
})
log.debug('tp price', tpPrice)
log.debug('item display', itemDisplay)
}
}
var integrationStatus = loadedInvoice.getValue({
fieldId: 'custbodyintegrationstatus'
})
log.debug('integration status', integrationStatus)
loadedInvoice.save()
return true;
})
} catch (error) {
log.error("Error in Scheduled Script", error.toString());
}
}
return {
execute: execute
};
});
Samantha Solomon
03/12/2024, 8:34 PM{
"type": "error.SuiteScriptError",
"name": "SSS_INVALID_SUBLIST_OPERATION",
"message": "You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.",
"id": "",
"stack": [
"Error\n at RecordInvoker.removeLine (suitescript/resources/javascript/record/serverRecordService.js:333:5)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)\n at /SuiteScripts/fix-wsi-invoices-scheduled.js:37:43\n at Object.execute (/SuiteScripts/fix-wsi-invoices-scheduled.js:15:42)"
],
"cause": {
"type": "internal error",
"code": "SSS_INVALID_SUBLIST_OPERATION",
"details": "You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.",
"userEvent": null,
"stackTrace": [
"Error\n at RecordInvoker.removeLine (suitescript/resources/javascript/record/serverRecordService.js:333:5)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)\n at /SuiteScripts/fix-wsi-invoices-scheduled.js:37:43\n at Object.execute (/SuiteScripts/fix-wsi-invoices-scheduled.js:15:42)"
],
"notifyOff": false
},
"notifyOff": false,
"userFacing": true
}
Anthony OConnor
03/12/2024, 9:13 PMAnthony OConnor
03/12/2024, 9:17 PMfor (var i = promotionsLineCount; i > 0; i--) {...}
should be rewritten as
for (var i = promotionsLineCount-1; i >= 0; i--) {...}
need to change the i > 0 to i>=0 tooAnthony OConnor
03/12/2024, 9:19 PMSamantha Solomon
03/12/2024, 9:42 PMSamantha Solomon
03/12/2024, 9:43 PMAnthony OConnor
03/12/2024, 10:44 PMSamantha Solomon
03/12/2024, 10:55 PMec
03/13/2024, 12:27 AM