Netsuite保存搜索到Suitelet子列表 [英] Netsuite Saved Search to Suitelet Sublist

查看:257
本文介绍了Netsuite保存搜索到Suitelet子列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我已创建的自定义保存搜索中的数据填充套件中的子列表。我的问题是子列表只填充与我正在进行的已保存搜索的类型对应的字段中的数据。例如,在这种情况下,保存的搜索是事务类型搜索。例如,如果我想引用带有已保存搜索的客户字段,请说名称和帐单地址,则此数据不会填充套件中的子列表。 事务记录本身中引用的所有其他字段都会很好地填充子列表。我只是想知道是否有人遇到过同样的问题,无论如何这里是我试图实现的代码。

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

    }


推荐答案

如果你查看nlobjSublist文档,您将看到sublist.setLineItemValues也可以获取哈希数组。工作原理是:

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

这篇关于Netsuite保存搜索到Suitelet子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆