【功能实现】在单据的列表,勾选行,执行数据库语句;
【优点】无论公有云、混合云还是私有云都可用;
【缺点】调试起来很麻烦;
【风险】一定要好好检查SQL语句,建议不要直接影响原有字段的值,用自定义字段先测试(完美熟练SQL的忽略);
【案列】采购订单列表加一个按钮,勾选行并点按钮后,更新明细单据体的自定义文本字段为“已执行”;
BOS列表菜单加好按钮,自定义字段加好(此处跳过)
注册列表Python插件:
import clr
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.App")
clr.AddReference("System")
clr.AddReference("System.Core")
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.App import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import *
from System import *
def AfterBarItemClick(e):
if(e.BarItemKey=="SBRA_tbButton_2"):
entryfid = []
rows = this.ListView.SelectedRowsInfo
for i in range(len(rows)):
entryfid.append(str(rows[i].EntryPrimaryKeyValue))
ids = list(set(entryfid))
s=','
filterstr = s.join(ids)
if(len(filterstr)==0):
this.View.ShowMessage("请先选择行!")
return
sqlstr = '''/*dialect*/update t_PUR_POOrderEntry set F_SBRA_TEXT2 = '已执行' where fentryid in ({0})'''.format(filterstr)
c = DBUtils.Execute(this.Context, sqlstr)
this.ListView.Refresh()
this.View.ShowMessage("选中了{0}行,更新成功{1}行".format(rows.Count,c))实现效果:
点击后:
最后附上语句截图,并写上一点注释:(一定要注意语句无空格、无空白行、Tab缩进正确等)