场景:
通过代码为某单据新增一条数据,带树形单据体
实现:
DynamicObject data = BusinessDataServiceHelper.newDynamicObject("单据标识");
data.set("billno", "963");
DynamicObjectCollection treeentryentity = data.getDynamicObjectCollection("kdec_treeentryentity");
DynamicObject treeentry = new DynamicObject(treeentryentity.getDynamicObjectType());
Long id = DBServiceHelper.genLongIds("tk_demo_tree", 1)[0];//tk_demo_tree为树形单据体表名
//**原因是树形单据体存在父子层级结构关系,必须设置pid以保证树形结构展示,故我们通过代码生成该单据体行数据的主键为了下一步设置pid
treeentry.set("Id", id);//设置该父行主键
treeentry.set("kdec_textfield2", "new year");
treeentry.set("kdec_integerfield2", 999);
DynamicObject treeentrySon = new DynamicObject(treeentryentity.getDynamicObjectType());
treeentrySon.set("pid",id);//设置该行的父行
treeentrySon.set("kdec_textfield2", "happy");
treeentrySon.set("kdec_integerfield2", 111);
treeentryentity.add(treeentry);
treeentryentity.add(treeentrySon);
Object[] ids = SaveServiceHelper.save(new DynamicObject[] {data});
效果:
预告:
花式单据列表❀
思考?
为什么一定要新增带有id的父行
推荐阅读