0

I'm new in netsuite and I have to prove myself front of my boss. My problem is how can I get to a sublist and retrieve a field linked to another field in an automatic way when creating a new line.

function taxCode_fieldChanged(context) {
 var stCodeTax = nlapiGetFieldValue('cust_taxcode');
 var labelCategory = nlapiGetFieldValue('name');
 var currentFormRec = context.currentRecord;
 var sublistName = context.sublistId;
 var sublistFieldName = context.fieldId;
 var lineNum = scriptContext.lineNum;
 var colNum = scriptContext.columnNum;

 for (var l = 1; l < lineNum; l++) {
  for (var c = 1; c < colNum; c++) {

   if (sublistName === 'Expenses' && sublistFieldName === 'Category') {
    currentFormRec.setValue({
     fieldId : 'tax code',
     value : stCodeTax
    });
   } 
  }
 }
}
Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66
spring_flower
  • 71
  • 1
  • 1
  • 9
  • scriptContext is not defined anywhere. Should it be context instead? Is the field in a matrix? – Maria Berinde-Tampanariu Dec 19 '17 at 18:13
  • yes the field in a matrix – spring_flower Dec 20 '17 at 07:41
  • 1
    In SuiteScript 2.0 rec.setValue() is used to set body fields. rec.setSublistValue() is used to set sublist fields and rec.setMatrixSublistValue() is used to set fields in a matrix, so perhaps the way the field is set should be reconsidered. I also noticed that it looks like SuiteScript 1.0 and 2.0 are used within the same script, which is not correct. What version is the script record? Which version do you want to write? Also, in the if statement the sublist and field name are usually lowercase. Hope this helps. – Maria Berinde-Tampanariu Dec 20 '17 at 08:02

0 Answers0