当需要在BeanShell中获取指定列表数据时,可使用本样例代码

分步指南

  1. Copy样例代码
  2. 修改listId,和appId变量




import org.joget.apps.app.dao.DatalistDefinitionDao;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.model.DatalistDefinition;
import org.joget.apps.app.service.AppService;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.datalist.model.*;
import org.joget.apps.datalist.service.DataListService;
import org.joget.commons.util.StringUtil;
import org.joget.plugin.base.DefaultApplicationPlugin;
import org.joget.plugin.base.PluginManager;


String appId = "vpsChatRobot";
String dataListId = "list_searchSalesman";

protected String getValue(Object o, String name) {
    String value = "";
    try {
        Object v = DataListService.evaluateColumnValueFromRow(o, name);
        if (v != null) {
            return v.toString();
        }
    } catch (Exception var5) {
    }
    return value;
}

AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
DataListService dataListService = (DataListService) AppUtil.getApplicationContext().getBean("dataListService");
DatalistDefinitionDao datalistDefinitionDao = (DatalistDefinitionDao) AppUtil.getApplicationContext().getBean("datalistDefinitionDao");

Long appVersion = appService.getPublishedVersion(appId);
AppDefinition appDef = appService.getAppDefinition(appId, appVersion.toString());
DatalistDefinition datalistDefinition = datalistDefinitionDao.loadById(dataListId,appDef);
DataList list = dataListService.fromJson(datalistDefinition.getJson());
Map<String, String[]> parameters = StringUtil.getUrlParams("d-6044013-fn_weekNum=10");//过滤字段
list.setRequestParamMap(parameters);
DataListCollection data = list.getRows();
for(Iterator iterator = data.iterator(); iterator.hasNext();){
    Object row = iterator.next();
    String content = getValue(row,"content");//列名
    System.out.println(content);
}