解答:
数据保存过程遇到的一些问题,如(1)数据保存成功,列表无数据,(2)代码调用saveOperate保存不成功(校验不通过检查)
1、SaveServiceHelper.save的调用过程
插件代码
String entityName = "kdec_pur_apply";
DynamicObject obj = BusinessDataServiceHelper.newDynamicObject(entityName);
CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule(obj.getDataEntityType().getName(), obj, null);
String number = CodeRuleServiceHelper.getNumber(codeRule, obj);
obj.set("billno", number);
obj.set("kdec_billnofield", number);
obj.set("billstatus", "A");
obj.set("creator", RequestContext.get().getUserId());
obj.set("kdec_applyorg", RequestContext.get().getOrgId());
obj.set("kdec_textfield1", "可见1");
DynamicObjectCollection col = obj.getDynamicObjectCollection("kdec_entryentity");
DynamicObjectType type = col.getDynamicObjectType();
DynamicObject item = new DynamicObject(type);
String materPk = "931963022627307520";
item.set("kdec_materielfield", materPk);
item.set("kdec_pricefield", new BigDecimal("23.7"));
col.add(item);
obj.set("kdec_entryentity", col);
if (obj != null) {
// Object [] o = SaveServiceHelper.save(new DynamicObject[] {obj});
// if(o.length>0) {
// }
OperationResult result = SaveServiceHelper.saveOperate(entityName, new DynamicObject[] {obj},OperateOption.create());
if(result.isSuccess()&&result.getAllErrorInfo()==null) {
}
}
(1)SaveServiceHelper.class
(2)BusinessDataWriter.class
(3)DataManagerImplement.class
(4)OrmDBTasks.class
(5)BatchInsertTask.class
(6)DBImpl.class查看传的参数和sql
在保存数据出现问题时,可以在这个类打断点,检查sql和参数是否正确等
2、SaveServiceHelper.saveOperate
(1)SaveServiceHelper.class
接下来的步骤参考https://club.kdcloud.com/article/136924752286676736
推荐阅读