1、多选基础资料是需要配置表去存数据,如果未设置表名,在单据打开时,该字段为空
2、后台存值 (操作插件)将单test01的币别1赋值给新建单据的币别2
eq:批量存数据,用List,不能在for里面循环存数据
保存后
package kd.bos.ecos; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.args.BeginOperationTransactionArgs; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; public class TestDemoOp extends AbstractOperationServicePlugIn{ // 币别1 private final static String KEY_MULBASEDATAFIELDO = "kdec_mulbasedatafield"; // 币别2 private final static String KEY_MULBASEDATAFIELDT = "kdec_mulbasedatafield1"; // 测试单据表单 private final static String KEY_TESTBILL_FORMID = "kdec_testbill1030"; @Override public void beginOperationTransaction(BeginOperationTransactionArgs e) { DynamicObject[] datas = e.getDataEntities(); for (DynamicObject dynamicObject : datas) { DynamicObject data = BusinessDataServiceHelper.loadSingle(KEY_TESTBILL_FORMID, "id,billno,kdec_mulbasedatafield", new QFilter[] { new QFilter("billno", QCP.equals, "test01") }); DynamicObjectCollection currencys = data.getDynamicObjectCollection(KEY_MULBASEDATAFIELDO); DynamicObjectType type = currencys.getDynamicObjectType(); DynamicObjectCollection newcu = new DynamicObjectCollection(); for (DynamicObject dynamicObject2 : currencys) { DynamicObject cu = dynamicObject2.getDynamicObject("fbasedataid"); DynamicObject obj = new DynamicObject(type); obj.set("fbasedataid", cu); if(obj!=null) { newcu.add(obj); } } dynamicObject.set(KEY_MULBASEDATAFIELDT, newcu); } e.setDataEntities(datas); } }
DynamicObjectCollection currencys = data.getDynamicObjectCollection(KEY_MULBASEDATAFIELDO);
DynamicObjectType type = currencys.getDynamicObjectType();
DynamicObjectCollection newcu = new DynamicObjectCollection();
for (DynamicObject dynamicObject2 : currencys) {
DynamicObject cu = dynamicObject2.getDynamicObject("fbasedataid");
DynamicObject obj = new DynamicObject(type);
obj.set("fbasedataid", cu);
if(obj!=null) {
newcu.add(obj);
}
}
dynamicObject.set(KEY_MULBASEDATAFIELDT, newcu);
3、后台取值(列表插件)
@Override
public void itemClick(ItemClickEvent evt) {
String key = evt.getItemKey();
// 获取多选基础资料值
if (StringUtil.equals("kdec_baritemap", key)) {
BillList billList = this.getControl("billlistap");
ListSelectedRowCollection listSelectedRowCollection = billList.getSelectedRows();
if (listSelectedRowCollection.size() > 0) {
Object pk = listSelectedRowCollection.get(0).getPrimaryKeyValue();
//不用QueryServiceHelper查,QueryServiceHelper查出数据是平铺的,无结构化
DynamicObject data = BusinessDataServiceHelper.loadSingle(pk, KEY_TESTBILL_FORMID, "id,billno,kdec_mulbasedatafield");
DynamicObjectCollection currencys = data.getDynamicObjectCollection(KEY_MULBASEDATAFIELDO);
if (currencys != null && currencys.size() > 0) {
StringBuffer messag = new StringBuffer();
for (DynamicObject currency : currencys) {
DynamicObject currencyObj = currency.getDynamicObject("fbasedataid");
String name = currencyObj.getString("name");
messag.append(name).append(",");
}
if (messag != null && messag.length() > 0) {
this.getView().showMessage(messag.deleteCharAt(messag.length() - 1).toString());
}
}
} else {
this.getView().showTipNotification("请选择获取多选基础资料的数据!!!");
}
}
}
4、前端直接赋值,参考(表单插件)
@Override
public void itemClick(ItemClickEvent evt) {
String key = evt.getItemKey();
// 获取多选基础资料值
if (StringUtil.equals("kdec_baritemap", key)) {
// 获取币别1的值
DynamicObjectCollection currency1 = (DynamicObjectCollection) this.getModel()
.getValue(KEY_MULBASEDATAFIELDO);
if (currency1 != null && currency1.size() > 0) {
// 将币别1赋值给币别2
this.getModel().setValue(KEY_MULBASEDATAFIELDT, currency1);
int index = this.getModel().createNewEntryRow("kdec_entryentity");
this.getModel().setValue(KEY_MULBASEDATAFIELDTH, currency1, index);
} else {
this.getView().showTipNotification("请选择获取多选基础资料的数据!!!");
}
}
}
5、附件字段类似,赋值也可以参照,附件字段绑定的基础资料是bos_attachment
demo.rar(2.56KB)
推荐阅读