多选基础资料 取值、存值原创
金蝶云社区-生态
生态
13人赞赏了该文章 8,289次浏览 未经作者许可,禁止转载编辑于2020年12月02日 10:57:12

1、多选基础资料是需要配置表去存数据,如果未设置表名,在单据打开时,该字段为空

image.png

2、后台存值 (操作插件)将单test01的币别1赋值给新建单据的币别2

    eq:批量存数据,用List,不能在for里面循环存数据

image.png

保存后

image.png

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、后台取值(列表插件)

image.png


       @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、前端直接赋值,参考(表单插件)

image.png


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

图标赞 13
13人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!