在论坛CQ周玉立前辈以及Login255前辈基础上优化了下SQL,用于获取主任岗部门
CQ周玉立:Python获取当前用户对应的员工
Login255:Python表单插件获取用户对应的员工和部门
Python表单插件获取用户对应的员工和主任岗部门,红色字体为调整地方
#参考代码
#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('System.Data')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.ServiceHelper')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from System import *
from System.Data import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
empId = 0;
deptId = 0;
def OnInitialize(e):
userID=str(this.Context.UserId);
sqlGetEmpId = ("""SELECT E.FID,DPL.FDEPTID AS DEPTID FROM T_SEC_USER U
INNER JOIN T_HR_EMPINFO E ON (U.FLINKOBJECT = E.FPERSONID)
INNER JOIN T_HR_EMPINFO_L EL ON (EL.FID = E.FID AND EL.FLOCALEID = 2052)
INNER JOIN T_BD_STAFF ST ON ST.FEMPINFOID = EL.FID
INNER JOIN T_BD_STAFFPOSTINFO ZG ON ZG.FSTAFFID=ST.FSTAFFID
INNER JOIN T_BD_DEPARTMENT_L DPL ON DPL.FDEPTID = ST.FDEPTID
WHERE ZG.FISFIRSTPOST='1' AND U.FUserId={0} """).format(userID);
global empId, deptId;
DataSet = DBServiceHelper.ExecuteDataSet(this.Context,sqlGetEmpId).Tables[0];
empId=DataSet.Rows[0]["FID"] if DataSet.Rows.Count>0 else 0;
deptId=DataSet.Rows[0]["DEPTID"] if DataSet.Rows.Count>0 else 0;
def AfterCreateNewData(e):
global empId,deptId;
this.Model.SetItemValueByID("F_EmpId", empId, 0); #申请人,需根据表单字段做相应修改
this.Model.SetItemValueByID("F_DeptId", deptId, 0); #申请部门,需根据表单字段做相应修改
效果根据设置主任岗位,带出对应所属主任岗部门
获取当前用户所对应员工和主任岗部门.zip(1.08KB)