1
votes

I am trying to populate a sublist in a suitelet with data from a custom saved search that I have already created. My problem is that the sublist is only populating data from fields that correspond to the "type" of saved search I am doing. For example, in this instance the saved search is a "transaction" type search. If, for example, I want to reference a customer field withing the saved search, say "Name" and "Billing Address", this data will not populate the sublist in the suitelet. All other fields that are being referenced in the Transaction record itself populate the sublist fine. I was just wondering if anyone has ever run into the same issue, anyways here's the code I'm trying to implement.

 var form,
    sublist;

    //GET
if (request.getMethod() == 'GET')
    {      
        //create form
        form = nlapiCreateForm('Test Custom Suitelet Form', false);

        //create sublist to show results
        sublist = form.addSubList('custpage_sublist_id', 'list', 'Item List');


        //form buttons
        form.addSubmitButton('Submit');
        form.addResetButton('Reset');

        // run existing saved search
        var searchResults = nlapiSearchRecord('transaction','customsearchID');
        var columns = searchResults[0].getAllColumns();

        // Add the search column names to the sublist field
        for ( var i=0; i< columns.length; i++ )
            {
                sublist.addField(columns[i].getName() ,'text', columns[i].getLabel() ); 
                nlapiLogExecution('DEBUG', 'Column Label',columns[i].getLabel());
            }

        //additional sublist fields
        sublist.addMarkAllButtons();
        sublist.addField('custfield_selected', 'checkbox', 'Selected');

        sublist.setLineItemValues(searchResults)

        response.writePage(form);

    }
1
I've tried several approaches myself and cannot find out the correct answer. I tried concatenating the join name with the column name in various combinations as this is how NetSuite represents the search result, but that does not work. Tried, but failed. Would be very interested if anyone else finds correct answer. On a slightly unrelated note, instead of hard-coding 'text', I believe you can use columns[i].getType() in your call to sublist.addFielderictgrubaugh
Thank you for your help. I will definitely try out your getType() method. The reason I didn't use it here is because those are just the column "title" names if you will. Their type doesn't really matter as they are just text on top of the column. I've tried so many different approaches to get it to work, I'm very interested to see if someone finds a way as well.L.B.

1 Answers

2
votes

If you review the nlobjSublist docs you'll see that sublist.setLineItemValues can also take an array of hashes. What does work is:

function getJoinedName(col) {
    var join = col.getJoin();
    return join ? col.getName() + '__' + join : col.getName();
}
searchResults[0].getAllColumns().forEach(function(col) {
    sublist.addField(getJoinedName(col), 'text', col.getLabel());
    nlapiLogExecution('DEBUG', 'Column Label', col.getLabel());
});
var resolvedJoins = searchResults.map(function(sr) {
    var ret = {
        id: sr.getId()
    };
    sr.getAllColumns().forEach(function(col) {
        ret[getJoinedName(col)] = sr.getText(col) || sr.getValue(col);
    });
    return ret;
});
sublist.setLineItemValues(resolvedJoins);