Populate Suitelet Sublist from a Saved Search with Formulas in the Search

折月煮酒 提交于 2019-12-11 10:31:36

问题


@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


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/52616401/populate-suitelet-sublist-from-a-saved-search-with-formulas-in-the-search

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