常用场景:根据用户的情况,在表单中选择用户,将现在需要审批处理的节点,转给另一个用户进行审批。
参考脚本:- (function(){
- var doc = getCurrentDocument();
- var userIds = getWebUser().getId();
- var user = doc.getItemValueAsString("审批人"); //表单字段
- var docProcess = getDocProcess(getApplication());
- var docids = splitText(user, ";");
- var userlist = createObject("java.util.ArrayList");
- var list = new Packages.java.util.ArrayList();
- for (var i = 0; i < docids.length; i++) {
- if(docids != null) {
- list.add(docids[i]);
- }
- }
- var params = getParamsTable();
- params.setParameter("auditorList",list);
- var currNodeId= "1617073756399"; //当前节点ID
- params.setParameter("_currid", currNodeId);
- var actorJson = new Packages.net.sf.json.JSONObject();
- actorJson.put(currNodeId,list);
- doc.setAuditorList(actorJson.toString());
- docProcess.doChangeAuditor(doc,params,getWebUser());
- })();
复制代码 补充:- /**
- * 批量更新当前流程节点审批人
- * @param docid
- * 文档id
- * @param applicationId
- * 软件id
- * @param content 请求包体
- * @return
- * @throws Exception
- */
- @PutMapping("/domain/workflow/approvers/batch")
- @ResponseStatus(HttpStatus.OK)
- @ApiOperation(value = "批量更新当前流程节点审批人", notes = "批量更新当前流程节点审批人")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "content",value = "请求包体",required = true,paramType = "body",dataType = "string")
- })
- public Resource batchuUpdateApprovers(@RequestBody String content) {
- try {
- JSONObject jsonObject = JSONObject.fromObject(content);
- List<String> userIds = jsonObject.getJSONArray("userIds");
- JSONArray docs = jsonObject.getJSONArray("docs");
- WebUser user = WebUser.getAdminUser(request);
- List<String> errorMsg = new ArrayList<String>();
- int count = 0;
- for(Iterator<JSONObject> iterator = docs.iterator();iterator.hasNext();){
- try{
- JSONObject json = iterator.next();
- String docId = json.getString("docId");
- String applicationId = json.getString("applicationId");
- DocumentProcess process = (DocumentProcess)ProcessFactory.createRuntimeProcess(DocumentProcess.class, applicationId);
- Document doc = (Document)process.doView(docId);
- if(doc == null){
- count++;
- errorMsg.add("第"+ count + "条处理失败。原因:数据不存在!");
- continue;
- }
- var params = createParamsTable();
- //ParamsTable params = new ParamsTable(getParams());
- params.setParameter("auditorList", userIds);
- FlowStateRT instance = doc.getState();
- if(instance == null){
- count++;
- errorMsg.add("第"+ count + "条处理失败。原因:当前流程实例不存在!");
- continue;
- }
- NodeRT nodeRT = instance.getNoderts().iterator().next();
- if(nodeRT == null){
- count++;
- errorMsg.add("第"+ count + "条处理失败。原因:当前节点实例不存在!");
- }
- String currNodeId = nodeRT.getNodeid();
- JSONObject actorJson = new JSONObject();
- actorJson.put(currNodeId, userIds);
- doc.setAuditorList(actorJson.toString());
- params.setParameter("_currid", currNodeId);
- process.doChangeAuditor(doc, params, user);
- doc.setEditAbleLoaded(false);
- MemoryCacheUtil.putToPrivateSpace(doc.getId(), doc, user);
- count++;
- } catch (Exception e){
- count++;
- errorMsg.add("第"+ count + "条处理失败。");
- }
- }
- if(errorMsg.isEmpty()){
- return success("ok", null);
- } else {
- return success("ok", errorMsg);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return error(500, e.getMessage(), null);
- }
- }
复制代码 |