Hi There
I have a client script running on a vendor bill.
If I try to save the record after placing it into edit mode, I get the following error:
I have not clicked into the sublist however.
This is the script
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(["N/record"], function (record) {
/**
* @param {ClientScriptContext.fieldChanged} context
*/
function fieldChanged(context) {
//the if condition ensures the field changed trigger does not execute on changes in sublist. setting this to
//!context.sublistid ensures changes in department field and location field for the sublist do not trigger the script
if (
!context.sublistId &&
(context.fieldId == "department" || context.fieldId == "location")
) {
log.debug("sublistId", context.sublistId)
log.debug("fieldId", context.fieldId)
var recordObj = context.currentRecord
var departmentMain = recordObj.getValue({ fieldId: "department" })
var locationMain = recordObj.getValue({ fieldId: "location" })
var expenseSublist = recordObj.getSublist({ sublistId: "expense" })
var expenseSublistLength = recordObj.getLineCount({
sublistId: "expense",
})
log.debug("department", departmentMain)
log.debug("location", locationMain)
log.debug("expenseSublist.length", expenseSublistLength)
for (var i = 0; i < expenseSublistLength; i++) {
recordObj.selectLine({
sublistId: "expense",
line: i,
})
var departmentLine = recordObj.setCurrentSublistValue({
sublistId: "expense",
fieldId: "department",
value: departmentMain,
ignoreFieldChange: true,
})
var locationLine = recordObj.setCurrentSublistValue({
sublistId: "expense",
fieldId: "location",
value: locationMain,
ignoreFieldChange: true,
})
recordObj.commitLine({ sublistId: "expense" })
log.debug("department", departmentLine)
log.debug("location", locationLine)
}
}
}
/**
* @param {ClientScriptContext.postSourcing} context
*/
function postSourcing(context) {
var currentRecord = context.currentRecord
var sublistName = context.sublistId
var sublistFieldName = context.fieldId
var line = context.line
var departmentMain = currentRecord.getValue({ fieldId: "department" })
var locationMain = currentRecord.getValue({ fieldId: "location" })
if (sublistName === "expense" && sublistFieldName === "account") {
}
var expenseSublist = currentRecord.getSublist({ sublistId: "expense" })
var expenseSublistLength = currentRecord.getLineCount({
sublistId: "expense",
})
log.debug("department-main", departmentMain)
log.debug("location-main", locationMain)
currentRecord.setCurrentSublistValue({
sublistId: "expense",
fieldId: "department",
value: departmentMain,
ignoreFieldChange: false,
})
currentRecord.setCurrentSublistValue({
sublistId: "expense",
fieldId: "location",
value: locationMain,
ignoreFieldChange: false,
})
}
return {
fieldChanged: fieldChanged,
postSourcing: postSourcing,
}
})
Is there something in this script which is causing this?
Thanks