【泛微OA】将明细表店铺赋值给主表店铺店铺/【SQL】实现多个数据返回值拼接

方法一:通过sql语句实现

doFieldSQL(" SELECT   STUFF(( SELECT ',' + t1.dp FROM   (select distinct a.dp from formtable_main_346_dt1 as a inner join formtable_main_346 as b on a.mainid=b.id and  b.lcbm='$main.lcbm$')  as t1 FOR XML PATH('') ), 1, 1, '') ")

知识点讲解:

SELECT   STUFF(( SELECT ',' + A.Name 
					FROM   A     
					FOR XML PATH('') ), 1, 1, '')

--for xml path() 函数:这里用来做字符串拼接
--STUFF()函数:函数用于删除指定长度的字符,并可以在制定的起点处插入另一组字符。
-- select stuff(列名,开始位置,长度,替代字符串)

方法二:通过JS脚本实现

<script>
$(document).ready(function () {
 add();
})

//field25750主表字段
//field25678明细表字段
function add() {
    WfForm.bindDetailFieldChangeEvent("field25678", function (id, rowIndex, value) {
        WfForm.changeFieldValue("field25750", {
            value: ""
        });
        var map = new Map();
        var str = "";
        console.log("WfForm.bindDetailFieldChangeEvent--", id, rowIndex, value);
        var arr = WfForm.getDetailAllRowIndexStr("detail_1");
        var arrs = arr.split(",");
        for (var i = 0; i < arrs.length; i++) {
            var see = WfForm.getFieldValue("field25678_" +arrs[i]);
            var sed = WfForm.getBrowserShowName("field25678_" + arrs[i]);
            if (see.indexOf(",") != -1) {
                var sees = see.split(",");
                var seds = sed.split(",");
                for (var j = 0; j < sees.length; j++) {
                    if (map.get(sees[j]) == undefined) {
                        window._writeBackData("field25750", 1, {
                            id: sees[j],
                            name: seds[j]
                        }, {
                            replace: false,
                            isSingle: false
                        });
                        map.set(sees[j], seds[j]);
                    }
                }
            } else {
                if (map.get(see) == undefined) {
                    window._writeBackData("field25750", 1, {
                        id: see,
                        name: sed
                    }, {
                        replace: false,
                        isSingle: false
                    });
                    map.set(see, sed);
                }
            }

        }

        console.log(str);
    });

}
</script>


//店铺+货品

<script>
$(document).ready(function () {
 add();
 addhp();
    $("i#delbutton0").click(function () {
        add();
        addhp();
    })

})

//field25750主表字段
//field25678明细表字段
function add() {
    WfForm.bindDetailFieldChangeEvent("field25678", function (id, rowIndex, value) {
        WfForm.changeFieldValue("field25750", {
            value: ""
        });
        var map = new Map();
        var str = "";
        console.log("WfForm.bindDetailFieldChangeEvent--", id, rowIndex, value);
        var arr = WfForm.getDetailAllRowIndexStr("detail_1");
        var arrs = arr.split(",");
        for (var i = 0; i < arrs.length; i++) {
            var see = WfForm.getFieldValue("field25678_" +arrs[i]);
            var sed = WfForm.getBrowserShowName("field25678_" + arrs[i]);
            if (see.indexOf(",") != -1) {
                var sees = see.split(",");
                var seds = sed.split(",");
                for (var j = 0; j < sees.length; j++) {
                    if (map.get(sees[j]) == undefined) {
                        window._writeBackData("field25750", 1, {
                            id: sees[j],
                            name: seds[j]
                        }, {
                            replace: false,
                            isSingle: false
                        });
                        map.set(sees[j], seds[j]);
                    }
                }
            } else {
                if (map.get(see) == undefined) {
                    window._writeBackData("field25750", 1, {
                        id: see,
                        name: sed
                    }, {
                        replace: false,
                        isSingle: false
                    });
                    map.set(see, sed);
                }
            }

        }

        console.log(str);
    });

}
//field26002主表字段
//field25657明细表字段
function addhp() {
    WfForm.bindDetailFieldChangeEvent("field25657", function (id, rowIndex, value) {
        WfForm.changeFieldValue("field26002", {
            value: ""
        });
        var map = new Map();
        var str = "";
        console.log("WfForm.bindDetailFieldChangeEvent--", id, rowIndex, value);
        var arr = WfForm.getDetailAllRowIndexStr("detail_1");
        var arrs = arr.split(",");
        for (var i = 0; i < arrs.length; i++) {
            var see = WfForm.getFieldValue("field25657_" +arrs[i]);
            var sed = WfForm.getBrowserShowName("field25657_" + arrs[i]);
            if (see.indexOf(",") != -1) {
                var sees = see.split(",");
                var seds = sed.split(",");
                for (var j = 0; j < sees.length; j++) {
                    if (map.get(sees[j]) == undefined) {
                        window._writeBackData("field26002", 1, {
                            id: sees[j],
                            name: seds[j]
                        }, {
                            replace: false,
                            isSingle: false
                        });
                        map.set(sees[j], seds[j]);
                    }
                }
            } else {
                if (map.get(see) == undefined) {
                    window._writeBackData("field26002", 1, {
                        id: see,
                        name: sed
                    }, {
                        replace: false,
                        isSingle: false
                    });
                    map.set(see, sed);
                }
            }

        }

        console.log(str);
    });

}

</script>


THE END
分享
二维码
打赏
海报
【泛微OA】将明细表店铺赋值给主表店铺店铺/【SQL】实现多个数据返回值拼接
方法一:通过sql语句实现 doFieldSQL(" SELECT STUFF(( SELECT ',' + t1.dp FROM (select distinct a.dp from formtable_main_346_dt1 as a inner joi……
<<上一篇
下一篇>>