找回密码
 注册成为天翎用户
查看: 1078|回复: 7

[已解决] 父表单如何获取子表单数据,合并后填入父表单中?

[复制链接]
sorcery 发表于 2021-12-24 13:38:49 | 显示全部楼层 |阅读模式
【myApps/OBPM版本号】:v5.0- sp XX
【浏览器类型】:Chrome/其他
【联系方式-QQ】:190407227
【联系电话】:    请留下您的联系电话,以便技术同事更好解决您的问题
【问题描述】:
第一个问题:父表单通过相同字段获取到子表单多行数据,获取到的数据后合并填入父表单中某个文本框
脚本如下:
var user = getItemValue("委托编号");//父表单与子表单有同样的字段委托编号
var rtn = '';
if(user!=null && user.trim().length()>0){
var sql="select item_委托编号,group_concat(distinct item_检测依据) as item_检测依据  from tlk_样品详情表单 where item_委托编号='"+user+"'  group by item_委托编号”;//在mysql中可以运行
var query = queryBySQL(sql);
if(query!=null){
              var iter  =query.iterator();
              if(iter != null && iter.hasNext()){
                       doc = iter.next();
                       rtn = doc.getItemValueAsString("检测依据");   //根据查询的结果获取合并后的字段
              }        
}
}
rtn;


脚本哪里不正确?

第二个问题:父子表单,删除父表单后,数据库中子表单数据还是存在,子表单是通过元素插入父表单中的,有父子关系



1、问题描述最好图文并茂,如有视频/脚本可直接放出,这样技术同事在处理该问题时效率更加高效哦~
2、如果该问题已得到解决,请在该帖子下回复\"已解决可结帖\"
Aio 发表于 2021-12-24 15:21:47 | 显示全部楼层
第一个问题:你的脚本是用闭包的形式写的话,最后返回的rtn需要用return,而且你用 queryBySQL查应该是拿到多条数据吧,这样的话 rtn = doc.getItemValueAsString("检测依据");不是拼接合并吧,而是每一次都去更新拿到最新的值,要用 rtn += doc.getItemValueAsString("检测依据");才是拼接吧。
回复

使用道具 举报

Aio 发表于 2021-12-24 15:25:17 | 显示全部楼层
第二个问题是个bug,目前正在修复中
回复

使用道具 举报

 楼主| sorcery 发表于 2021-12-24 16:21:55 | 显示全部楼层
根据您的提示,脚本修改后报错:
var user = getItemValue("委托编号");
var rtn = '';
if(user!=null && user.trim().length()>0){
var sql="select item_委托编号,group_concat(distinct item_检测依据) as item_检测依据  from tlk_样品详情表单 where item_委托编号='"+user+"'  group by item_委托编号";
var query = queryBySQL(sql);
if(query!=null){
              var iter  =query.iterator();
              if(iter != null && iter.hasNext()){
                       doc = iter.next();
                     rtn += doc.getItemValueAsString("检测依据");   
              }        
}
}
return rtn;


错误如下:
Caused by: java.lang.Exception: Field:试验依据-值脚本出错 <br>JavaScriptRunning:[Form.委托表单.Field(__qDSp2cxOBGM41WCz5oS).试验依据.ValueScript]: invalid return (Form.委托表单.Field(__qDSp2cxOBGM41WCz5oS).试验依据.ValueScript#14)
        at cn.myapps.runtime.dynaform.form.ejb.Form.recalculateDocument(Form.java:1759)
        at cn.myapps.runtime.dynaform.form.ejb.Form.createDocument(Form.java:1139)
        at cn.myapps.runtime.dynaform.form.ejb.Form.createDocument(Form.java:1066)
        at cn.myapps.runtime.dynaform.form.ejb.Form.createDocument(Form.java:1030)
        at cn.myapps.runtime.dynaform.document.ejb.DocumentProcessBean.doNewWithFlowPermission(DocumentProcessBean.java:167)
        at cn.myapps.runtime.dynaform.form.service.FormRunTimeServiceImpl.newDocument(FormRunTimeServiceImpl.java:1109)
        at cn.myapps.runtime.dynaform.form.controller.FormController.newDocument(FormController.java:194)
        at sun.reflect.GeneratedMethodAccessor1803.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
        ... 56 more
Hibernate: select notificati0_.id as id1_3_, notificati0_.CREATE_TIME as CREATE_T2_3_, notificati0_.DOMAIN_ID as DOMAIN_I3_3_, notificati0_.LINK_PARAMS as LINK_PAR4_3_, notificati0_.MESSAGE_ID as MESSAGE_5_3_, notificati0_.MESSAGE_TYPE as MESSAGE_6_3_, notificati0_.MODULE as MODULE7_3_, notificati0_.RECEIVER_ID as RECEIVER8_3_, notificati0_.SENDER as SENDER9_3_, notificati0_.SENDER_ID as SENDER_10_3_, notificati0_.SUMMARY as SUMMARY11_3_ from mc_notification notificati0_ where notificati0_.RECEIVER_ID=?
Hibernate: select notificati0_.id as id1_3_, notificati0_.CREATE_TIME as CREATE_T2_3_, notificati0_.DOMAIN_ID as DOMAIN_I3_3_, notificati0_.LINK_PARAMS as LINK_PAR4_3_, notificati0_.MESSAGE_ID as MESSAGE_5_3_, notificati0_.MESSAGE_TYPE as MESSAGE_6_3_, notificati0_.MODULE as MODULE7_3_, notificati0_.RECEIVER_ID as RECEIVER8_3_, notificati0_.SENDER as SENDER9_3_, notificati0_.SENDER_ID as SENDER_10_3_, notificati0_.SUMMARY as SUMMARY11_3_ from mc_notification notificati0_ where notificati0_.RECEIVER_ID=?
Hibernate: select count(notice0_.id) as col_0_0_ from mc_notice notice0_ where notice0_.IS_READ=1
Hibernate: select count(comment0_.id) as col_0_0_ from mc_comment comment0_ where comment0_.IS_READ=1
Hibernate: select notificati0_.id as id1_3_, notificati0_.CREATE_TIME as CREATE_T2_3_, notificati0_.DOMAIN_ID as DOMAIN_I3_3_, notificati0_.LINK_PARAMS as LINK_PAR4_3_, notificati0_.MESSAGE_ID as MESSAGE_5_3_, notificati0_.MESSAGE_TYPE as MESSAGE_6_3_, notificati0_.MODULE as MODULE7_3_, notificati0_.RECEIVER_ID as RECEIVER8_3_, notificati0_.SENDER as SENDER9_3_, notificati0_.SENDER_ID as SENDER_10_3_, notificati0_.SUMMARY as SUMMARY11_3_ from mc_notification notificati0_ where notificati0_.RECEIVER_ID=?
Hibernate: select notificati0_.id as id1_3_, notificati0_.CREATE_TIME as CREATE_T2_3_, notificati0_.DOMAIN_ID as DOMAIN_I3_3_, notificati0_.LINK_PARAMS as LINK_PAR4_3_, notificati0_.MESSAGE_ID as MESSAGE_5_3_, notificati0_.MESSAGE_TYPE as MESSAGE_6_3_, notificati0_.MODULE as MODULE7_3_, notificati0_.RECEIVER_ID as RECEIVER8_3_, notificati0_.SENDER as SENDER9_3_, notificati0_.SENDER_ID as SENDER_10_3_, notificati0_.SUMMARY as SUMMARY11_3_ from mc_notification notificati0_ where notificati0_.RECEIVER_ID=?
Hibernate: select count(notice0_.id) as col_0_0_ from mc_notice notice0_ where notice0_.IS_READ=1
Hibernate: select count(comment0_.id) as col_0_0_ from mc_comment comment0_ where comment0_.IS_READ=1
回复

使用道具 举报

dlq 发表于 2021-12-26 20:07:25 | 显示全部楼层
sorcery 发表于 2021-12-24 16:21
根据您的提示,脚本修改后报错:
var user = getItemValue("委托编号");
var rtn = '';

// 参照这个取子表的数据呢?


        var doc = getCurrentDocument();
        var val = "";
      
        var childs = doc.getChilds("子表");//获取明细
                for (var it = childs.iterator(); it.hasNext();){
                        var data = it.next();
                        println("data--->"+data);
                        val += data.getItemValueAsString("商品名称")+"*"+ data.getItemValueAsString("商品数量")+";";
                        println("备注--->"+val);
                }
        return val;

回复

使用道具 举报

 楼主| sorcery 发表于 2021-12-27 11:20:34 | 显示全部楼层
楼上给的代码是获取字段,然后合并。
和我需要的功能不一样,我要实现的目标是,表中多行数据查询,提取有共同字段的数据合并,而不是一行中多个字段合并。
回复

使用道具 举报

 楼主| sorcery 发表于 2021-12-27 14:06:18 | 显示全部楼层
根据提示,做了修改,可以实现了
var rtn = "";
var doc = getCurrentDocument();
var childs = doc.getChilds("样品详情表单");
if (childs!=null && childs.size()>0){
    for(var it = childs.iterator();it.hasNext();){
         var subdoc = it.next();
        if (rtn.length>0) rtn = rtn+",";
        rtn +=subdoc.getItemValueAsString("检测依据");
    }
}
rtn;
回复

使用道具 举报

lillian828 发表于 2021-12-27 17:21:45 | 显示全部楼层
好的,有问题请继续发贴啊。
回复

使用道具 举报

本版积分规则

手机版|天翎MyApps技术社区 ( 粤ICP备11093750号 )

GMT+8, 2026-8-14 13:02

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表