以新增操作为例,新增如下,首先获取entityPK(参见4.2.),元数据查获取BOSType,如下图:
//创建值对象 function createNewData(entityPK) { var objectValue = new com.kingdee.eas.ep.DataBaseCustomInfo(); var entityBosType = "9DD486DB"; //实体的bosType,可通过[元数据检查]获得 objectValue.setBOSType(new com.kingdee.bos.util.BOSObjectType(entityBosType)); //实体的PK,可通过[元数据检查]获得 objectValue.setPK(new com.kingdee.bos.metadata.MetaDataPK(entityPK)); return objectValue; } var entityPK = "com.kingdee.eas.basedata.assistant.app.Termsofapply"; var object = createNewData(entityPK); //通过实体PK获取自定义基础资料或单据接口,所需参数为实体pk var bizInterface = com.kingdee.bos.BOSObjectFactory. createRemoteCommonBOSObject( new com.kingdee.bos.metadata.MetaDataPK(entityPK)); bizInterface.addnew(object); //新增 ((com.kingdee.eas.ep.DataBaseCustomInfo)object).setName(“TestName”); object.setId(opk.getKeyValue("id")); object.setName("myName"); bizInterface.update(opk,object);//更新 |
//更新值对象 //需要更新记录的id,实际调用过程可从参数等取得 var fid = "87aUzEo7QWiREPo/LfoyDp3Uhts=" var entityPK = "com.kingdee.eas.basedata.assistant.app.Termsofapply"; //通过实体PK获取自定义基础资料或单据接口,所需参数为实体pk var bizInterface = com.kingdee.bos.BOSObjectFactory. createRemoteCommonBOSObject( new com.kingdee.bos.metadata.MetaDataPK(entityPK)); //通过id(字符串型)创建ObjectUuidPK为更新方法所须参数类型 var opk = new com.kingdee.bos.dao.ormapping.ObjectUuidPK( com.kingdee.bos.util.BOSUuid.read(fid)); //取得原值对象 var object = bizInterface.getValue(opk); //更改值对象某些属性 object.setName("myTestUpdateName"); //更新 bizInterface.update(opk,object); |
//删除值对象 var fid = "87aUzEo7QWiREPo/LfoyDp3Uhts="//需要更新记录的id var entityPK = "com.kingdee.eas.basedata.assistant.app.Termsofapply"; var bizInterface = com.kingdee.bos.BOSObjectFactory. createRemoteCommonBOSObject( new com.kingdee.bos.metadata.MetaDataPK(entityPK)); var opk = new com.kingdee.bos.dao.ormapping.ObjectUuidPK( com.kingdee.bos.util.BOSUuid.read(fid)); bizInterface.deleteBatchData([opk]);//删除 |
注意: 值对象创建必须设置一个实体的bosType和PK,引擎是通过这两项进行ORMMapping的。删除、更新、查看等动作由于值对象都存在id,所以其可以自动解析获得,不需要手工设置bosType和PK。对于删除操作,需要用deleteBatchData,参数为ObjectUuidPK数组。