3

How to set sublist value when using in client script. I tried all the method but it's not working and returning the same error.

fieldChanged: function(context){
     
     var record = currentRecord.get();
     
     //var record = context.currentRecord; // not working
    
         
     if(context.fieldId =='custpage_cancel'){
         
         var objSublist = record.getSublist({  //returns sublist obj but can not set 
         sublistId: 'custpage_sublist'
         });
        
    
        objSublist.setSublistValue({  // Not working ERROR: objSublist.setSublistValue is not a function
            fieldId : 'custpage_id',
            line : 0,
            value : true
        });
        
        // record.setSublistValue({        // Not working ERROR: objSublist.setSublistValue is not a function
         // sublistId: 'custpage_sublist',
         // fieldId: 'custpage_id',
         // line: 0,
         // value: true
        // });
         
     }
 }

ERROR: Screenshot

Error ScreenShot

Community
  • 1
  • 1
Anurag Kumar
  • 165
  • 1
  • 6
  • 17

3 Answers3

6

Try selecting the line and set the value , In netsuite for current record they prefer to use select line and set values

var records = context.currentRecord
 var lineNum = records .selectLine({
    sublistId: 'custpage_sublist',
    line: 0
});

    records.setCurrentSublistValue({
                        sublistId: 'custpage_sublist',
                        fieldId: 'custpage_id',
                        value: true,
                        ignoreFieldChange: true
                    });
   records.commitLine({
                        sublistId: 'sublistidentire'
                    });
Edwin Thomas
  • 466
  • 4
  • 16
  • Right, just for clarity, you do not set field values on the `sublist` object but rather on the `record` object in memory. – erictgrubaugh May 18 '18 at 17:26
  • It depends on what type of script you are writing – Edwin Thomas May 19 '18 at 05:43
  • The explanation for this is the notion of Dynamic vs Static records : depending on the type of record (when you do a Load, you can specify what kind of record you want to use, but with context or currentRecord, you can not chose, you can find out the type by checking the help or by using log : you will see Dynamic or Static) some functions are not available : for example, you can selectLine with dynamic but with static you get the error "is not a function". – B. Assem Feb 26 '19 at 08:15
  • Are you trying to set this in beforeLoad or afterSumbit? – deilkalb Nov 12 '19 at 17:20
  • 1
    @nikhilmeth dude we are talking about client script – Edwin Thomas Nov 13 '19 at 09:11
0

try to do the same with a custom list sublist "list" and throw me error

enter image description here


User event Script

function beforeLoad(){

  var form = scriptContext.form;

  var sublistaAplicar=form.addSublist({
    id: 'custpage_invoice', 
    type: 'list',
    label: 'Facturas',
    tab: 'custpage_aplicar'
  });

  sublistaAplicar.addField({
    id : 'custpage_type',
    type : serverWidget.FieldType.TEXT,
    label : 'Type'
  });
}

client script.js

function validateField(scriptContext) {

  var currentRecord = scriptContext.currentRecord;

  var lineNum = currentRecord.selectLine({
    sublistId: 'custpage_invoice',
    line: 0
  });

  currentRecord.setCurrentSublistValue({
    sublistId: 'custpage_invoice',
    fieldId: 'custpage_type',
    value: 'test',
    ignoreFieldChange: true
  });
        
  currentRecord.commitLine({
    sublistId: 'custpage_invoice'
  });
}
Muhammad Noman
  • 1,344
  • 1
  • 14
  • 28
-4

You may need to use the command of inserting new line first before you select the line when you are on the client script.