1.功能描述
系统提供一些比较常用的脚本,可在写脚本的地方引用,如:事件脚本、催办设置、跳转规则设置、初始赋值等地方可使用
2.操作指引
第一步:在后端代码中开发好人员脚本(请参考文档[宏天软件EIPSAAS_流程脚本(常用脚本、人员脚本)开发说明])
第二步:【流程中心】→【辅助功能】→【常用脚本】;
第三步:点击“添加”按钮;
第四步:设置常用脚本;
第五步:单击“保存”。
2.6.5 常用脚本使用说明
1.获取用户组织架构信息脚本
| 序号 | 脚本 | 接口描述 | 
| 1 | getCurrentUserId | 获取当前用户ID,以set形式返回 | 
| 2 | getCurrentUser | 获取当前用户对象(对象中包括用户id、账号、组织等信息) | 
| 3 | getCurrentUserName | 获取当前用户名称 | 
| getCurrentUserId | 获取当前用户ID | |
| getCurrentAccount | 获取当前用户帐号 | |
| 4 | getCurrentGroupId | 获取当前用户的当前组织id | 
| getCurrentGroupName | 获取当前用户的当前组织名称 | |
| 5 | getIUserMainOrgName | 获取当前用户的主组织名称 | 
| getIUserMainOrgID | 获取当前用户的主组织ID | |
| 6 | getIUserPostName | 获取当前用户的所有岗位名称 | 
| getIUserPostID | 获取当前用户的所有岗位ID | |
| 7 | getIUserRoleName | 获取当前用户的所有角色名称 | 
| getIUserRoleID | 获取当前用户的所有角色ID | |
| 8 | getFillOrgId | 获取当前用户填制组织id(获取当前用户所属组织级别为2的组织) | 
| getFillOrg | 获取当前用户填制组织 | |
| 9 | getMainPostName | 获取当前用户主岗位内容 | 
| getCurrentMainPostName | 获取当前用户主岗位名称 | |
| getCurrentMainPostId | 获取当前用户主岗位ID | |
| getCurrentMainPostCode | 取当前用户主岗位编码 | |
| 10 | getRoles | 获取全部角色,并将其转化成流程审批对象 | 
| 11 | isUserInRole | 判断某个用户是否属于某个角色 | 
| 12 | isCurrentInRole | 判断当前用户是否有该角色 | 
| 13 | getUser | 根据用户id获取用户对象 | 
① getCurrentUserId获取当前用户ID,以set形式返回
| 输出参数 | ||
| 参数名称 | 类型 | 说明 | 
| Set<String> | Set | 用户id集合 | 
事件脚本使用示例:
scriptImpl.getCurrentUserIdSet();
初始赋值示例:
//将用户的id回填到表单字段
Set<String> set = scriptImpl.getCurrentUserIdSet();
sjjbfhz.get("data").put("spyj",String.join(",", set));
② getCurrentUser 获取当前用户对象(对象中包括用户id、账号、组织等信息)
| 输出参数 | ||
| 参数名称 | 类型 | 说明 | 
| Iuser | Iuser | 用户对象 | 
事件脚本使用示例:
//获取当前用户的id
//等同于:scriptImpl.getCurrentUserId();
scriptImpl.getCurrentUser().getUserId();
初始赋值示例:
//将当前用户的id回填到表单某个字段
sjjbfhz.get("data").put("spyj",scriptImpl.getCurrentUser().getUserId());
③ getCurrentUserName 、getCurrentUserId、getCurrentAccount 获取当前用户名称、获取当前用户ID、获取当前用户帐号
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getCurrentUserName | UserName | string | 用户名称 | 
| getCurrentUserId | UserId | string | 用户id | 
| getCurrentAccount | Account | string | 用户账号 | 
事件脚本使用示例:
//获取用户名称
scriptImpl.getCurrentUserName();
//获取用户id
scriptImpl.getCurrentUserId();
//获取用户账号
scriptImpl.getCurrentAccount();
初始赋值示例:
//将用户名称回填到表单字段中
sjjbfhz.get("data").put("dqyhmc",scriptImpl.getCurrentUserName());
//将当前用户的id回填到表单某个字段
sjjbfhz.get("data").put("spyj",scriptImpl.getCurrentUserId());
//将当前用户的账号回填到表单某个字段
sjjbfhz.get("data").put("spyj",scriptImpl.getCurrentAccount());
④ getCurrentGroupId、getCurrentGroupName 获取当前用户的当前组织id、组织名称
注:当前用户有主组织时,获取主组织信息,当前用户没有主组织时,获取第一个所属组织信息;
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getCurrentGroupId | GroupId | string | 用户组织id | 
| getCurrentGroupName | GroupName | string | 用户组织名称 | 
事件脚本使用示例:
//获取当前用户组织id scriptImpl.getCurrentGroupId(); //获取当前用户组织名称 scriptImpl.getCurrentGroupName();
初始赋值示例:
//将当前用户的组织id到表单某个字段
sjjbfhz.get("data").put("zzid",scriptImpl.getCurrentGroupId());
//将当前用户的组织id到表单某个字段
sjjbfhz.get("data").put("zzmc",scriptImpl.getCurrentGroupName());
⑤ getIUserMainOrgName、getIUserMainOrgID 获取当前用户的主组织名称、主组织ID
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getIUserMainOrgName | mainOrgName | string | 主组织名称 | 
| getIUserMainOrgID | MainOrgID | string | 主组织ID | 
事件脚本使用示例:
//获取当前用户组织名称
scriptImpl.getIUserMainOrgName();
//获取当前用户组织ID
scriptImpl.getIUserMainOrgID();
初始赋值示例:
//将当前用户的组织id到表单某个字段
sjjbfhz.get("data").put("yhsszz",scriptImpl.getIUserMainOrgName());
//将当前用户的组织id到表单某个字段
sjjbfhz.get("data").put("yhsszzid",scriptImpl.getIUserMainOrgID());
⑥ getIUserPostName、getIUserPostID获取当前用户的所有岗位名称、岗位ID
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getIUserPostName | PostName | Set<String> | 岗位名称集合 | 
| getIUserPostID | PostID | Set<String> | 岗位id集合 | 
事件脚本使用示例:
//获取当前用户的岗位名称集合
scriptImpl.getIUserPostName();
//获取当前用户的岗位ID集合
scriptImpl.getIUserPostID();
初始赋值示例:
//将用户的所有岗位名称回填到表单字段
Set<String> set = scriptImpl.getIUserPostName();
sjjbfhz.get("data").put("dqyhgw",String.join(",", set));
//将用户的所有岗位id回填到表单字段
Set<String> set = scriptImpl.getIUserPostID();
sjjbfhz.get("data").put("dqyhgwid",String.join(",", set));
⑦ getIUserRoleName、getIUserRoleID 获取当前用户的所有角色名称、角色ID
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getIUserRoleName | RoleName | Set<String> | 角色名称集合 | 
| getIUserRoleID | RoleID | Set<String> | 角色id集合 | 
事件脚本使用示例:
//获取当前用户所属角色名称集合
scriptImpl.getIUserRoleName();
//获取当前用户所属角色id集合
scriptImpl.getIUserRoleID();
初始赋值示例:
//将用户的所有角色名称回填到表单字段
Set<String> set = scriptImpl.getIUserRoleName();
sjjbfhz.get("data").put("js",String.join(",", set));
//将用户的所有角色id回填到表单字段
Set<String> set = scriptImpl.getIUserRoleID();
sjjbfhz.get("data").put("jsid",String.join(",", set));
⑧ getFillOrgId、getFillOrg 获取当前用户填制组织id、填制组织
注:获取的是当前用户所属组织的组织级别为2的组织
| 
 | 输入参数 | |||
| 脚本名称 | 参数名 | 类型 | 是否必须 | 说明 | 
| getFillOrgId | demId | string | TRUE | 维度id | 
| getFillOrg | demId | string | TRUE | 维度id | 
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getFillOrgId | FillOrgId | String | 填制组织id | 
| getFillOrg | 填制组织 | Map<String,String> | Id:填制组织id, code:填制组织编码, Name:填制组织名称 | 
事件脚本使用示例:
//获取当前用户填制单位id
scriptImpl.getFillOrgId("1258608622670319616");
//获取当前用户填制单位名称并更新到表单字段
Map<String,String> set = scriptImpl.getFillOrg("1258608622670319616");
a = set.get("name");
scriptImpl.updateMainField("jbsj","nr1",a);
初始赋值示例:
//获取当前用户填制单位名称、id,并回填到表单字段中
Map<String,String> set = scriptImpl.getFillOrg("1258608622670319616");
a = set.get("name");
b = set.get("id");
sjjbfhz.get("data").put("ejzz",a);
sjjbfhz.get("data").put("ejzzid",b);"
⑨ getMainPostName 获取当前用户主岗位内容
| 
 | 输入参数 | |||
| 脚本名称 | 参数名称 | 类型 | 是否必须 | 说明 | 
| getMainPostName | fileName | string | TRUE | 岗位对象里的属性名称 | 
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getMainPostName | Value | String | 获取的值 | 
事件脚本使用示例:
//获取主岗位id
scriptImpl.getMainPostName("id");
//获取主岗位名称
scriptImpl.getMainPostName("name");
初始赋值示例:
//将主岗位id回填到表单字段
sjjbfhz.get("data").put("dqyhgwid",scriptImpl.getMainPostName("id"));
//将主岗位名称回填到表单字段
sjjbfhz.get("data").put("dqyhgw",scriptImpl.getMainPostName("name"));
⑩ getCurrentMainPostName、getCurrentMainPostId、getCurrentMainPostCode 获取当前用户主岗位名称、主岗位ID、主岗位编码
| 
 | 输出参数 | ||
| 脚本名称 | 参数名称 | 类型 | 说明 | 
| getCurrentMainPostName | MainPostName | String | 主岗位名称 | 
| getCurrentMainPostId | MainPostId | String | 主岗位id | 
| getCurrentMainPostCode | MainPostCode | String | 主岗位编码 | 
事件脚本使用示例:
//获取当前用户主岗位名称,等同于:scriptImpl.getMainPostName("name");
scriptImpl.getCurrentMainPostName();
//获取当前用户主岗位id,等同于:scriptImpl.getMainPostName("id");
scriptImpl.getCurrentMainPostId();
//获取当前用户主岗位编码,等同于:scriptImpl.getMainPostName("code");
scriptImpl.getCurrentMainPostCode();
初始赋值示例:
//将主岗位id回填到表单字段
sjjbfhz.get("data").put("dqyhgw",scriptImpl.getCurrentMainPostName());
//将主岗位id回填到表单字段
sjjbfhz.get("data").put("dqyhgwid",scriptImpl.getCurrentMainPostId());
//将主岗位编码回填到表单字段
sjjbfhz.get("data").put("dqyhgwbm",scriptImpl.getCurrentMainPostCode());
⑪getRoles 获取全部角色,并将其转化成流程审批对象
| 输出参数 | ||
| 参数名称 | 类型 | 说明 | 
| bpmIdentity | Set<BpmIdentity> | 流程与组织挂接实体接口 | 
事件脚本使用示例:
scriptImpl.getRoles();
⑫isUserInRole 判断某个用户是否属于某个角色
| 输入参数 | ||||||
| 参数名称 | 类型 | 是否必须 | 说明 | |||
| account | string | TRUE | 用户账号 | |||
| roleAlias | string | TRUE | 角色别名 | |||
| 输出参数 | 
 | |||||
| 参数名称 | 类型 | 说明 | 
 | |||
| 
 | boolean | 是否属于某个角色 | 
 | |||
事件脚本使用示例:
scriptImpl.isUserInRole("zs","aa");
//可结合其他脚本使用,例:判断当前用户账号是否属于某个角色
scriptImpl.isUserInRole(scriptImpl.getCurrentAccount(),"rsgly")
初始赋值示例:
//判断当前用户是否属于“一般用户”角色
if(scriptImpl.isUserInRole(scriptImpl.getCurrentAccount(),"rsgly")){
sjjbfhz.get("data").put("spyj","当前用户属于“一般用户”角色");
}else{
sjjbfhz.get("data").put("spyj","当前用户不属于“一般用户”角色");
}
⑬ isCurrentInRole 判断当前用户是否有该角色
| 输入参数 | |||
| 参数名称 | 类型 | 是否必须 | 说明 | 
| roleAlias | string | TRUE | 角色别名 | 
| 输出参数 | ||
| 参数名称 | 类型 | 说明 | 
| 
 | boolean | 是否属于某个角色 | 
事件脚本使用示例:
scriptImpl.isCurrentInRole("csjs");
初始赋值示例:
//判断当前用户是否属于“一般用户”角色
if(scriptImpl.isCurrentInRole("rsgly")){
sjjbfhz.get("data").put("spyj","当前用户属于“一般用户”角色");
}else{
sjjbfhz.get("data").put("spyj","当前用户不属于“一般用户”角色");
}
⑭ getUser 根据用户id获取用户对象
| 输入参数 | |||
| 参数名称 | 类型 | 是否必须 | 说明 | 
| userId | string | TRUE | 用户id | 
| 输出参数 | ||
| 参数名称 | 类型 | 说明 | 
| IUser | IUser | 用户对象 | 
事件脚本使用示例:
scriptImpl.getUser("1");
2.更新/获取表单字段
| 序号 | 脚本 | 接口描述 | 
| 1 | updateMainField | 更新主表字段值 | 
| 2 | updateMainField | 根据实例id更新主表字段值 | 
| 3 | updateSubField | 更新子表某行数据的字段值
         
     发表评论
   | 
 
 
