Populate Suitelet Sublist from a Saved Search with

2019-08-09 17:49发布

@bknights posted an good answer to another question around populating a sublist in a suitelet.

However, my question follows on from that when using bk's code:

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

The above works with a standard search with no formulae... How can we do this when I have multiple search columns which are formulae?

Using API1.0

2条回答
一纸荒年 Trace。
2楼-- · 2019-08-09 18:04

You can just get all the columns of the search result. columns = result[0].getColumns(). The reference the column where the formula column is. So if you look in the UI and it is the third from the top, you can get the value using result[0].getValue(columns[2])

This solution is dependent on the order of rows not changing.

Also if your saved search has labels for the Formulas, you can just use the labels as the field id.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-09 18:20

In your search definition add a label to all formula columns. Then your column keys can be derived like:

function getJoinedName(col) {
    if(col.getName().indexOf('formula') === 0 && col.getLabel()){
      return 'lbl_'+ col.getLabel().toLowerCase();
    }
    var join = col.getJoin();
    return join ? col.getName() + '__' + join : col.getName();
}
查看更多
登录 后发表回答