Netsuite Saved Search to Suitelet Sublist

假如想象 提交于 2019-12-08 04:18:28

问题


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:


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);


来源:https://stackoverflow.com/questions/33742377/netsuite-saved-search-to-suitelet-sublist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!