Netsuite Saved Search to Suitelet Sublist

2019-05-29 08:02发布

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条回答
家丑人穷心不美
2楼-- · 2019-05-29 08:35

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);
查看更多
登录 后发表回答