VanMan
VanMan

Reputation: 13

How do I add lines of data to a Suitelet Sublist (serverWidget.createform.addSublist)

It seems that I am missing something when trying to add data to a form sublist I have created. The sublist is populated with the first row of data, but nothing else.
I've tried to use the list object for the ui, but it seems to be separate from the form. My goal here is to display a record, with several sublists (based on saved searches) that relate to that record.

Any help would be great.

Thank you

var mySearch = search1.load({
         id: 'customsearch511'
       });
var resultSet = mySearch.run();
var list = form.addSublist( {
          id: 'custpage_sublist',
          type : serverWidget.SublistType.LIST,
          label: 'Lines'
       });
resultSet.columns.forEach(function(col){// This adds columns to the sublist based on the search results
           list.addField({
                   id: col.name,
                   label: col.label,
                   type: serverWidget.FieldType.TEXT
                   });
           });
for(var i in results){
  var result = results[i];
  for(var k in result.columns){
    var test = result.columns[k];
    if(result.getText(result.columns[k])){ //This is to get the values of any select field in the search
        var fieldValue = result.getText(result.columns[k]
        )} 
    else{
        var fieldValue = result.getValue(result.columns[k]
        )};

    list.setSublistValue({
        id: result.columns[k].name,
        value: fieldValue,
        line: i                       
        });
    //Error out after the first row is entered.  When this loops back to the second line of the search results.          
    }
context.response.writePage(form);    

Upvotes: 0

Views: 3496

Answers (2)

Mac
Mac

Reputation: 1

can also try the higher performance number casting using "+":

list.setSublistValue({
   id: result.columns[k].name,
   value: fieldValue,
   line: +i                       
 });

Upvotes: 0

Mayur Savaliya
Mayur Savaliya

Reputation: 56

You just need to do small correction in your code and it will be fine.

var a = Number(i);
sublist.setSublistValue({
  id: result.columns[k].name,
  value: fieldValue,
  line: a
});

I have tested and it's working fine.

Upvotes: 1

Related Questions