场景说明

应用构建自建单据引用主组织,在新增态为主组织赋当前用户的默认值。

一、公式赋值

公式赋值要考虑新增态才赋值 所以公式配置在页面规则中

//组织id
getValue(#{"bd.staff.StaffMainJob"}$,"org_id","staff_id",getValue(#{"bd.staff.Staff"}$,"id","user_id",userId()))

//组织
getValue(#{"org.func.AdminOrg"}$,"name","id",getValue(#{"bd.staff.StaffMainJob"}$,"org_id","staff_id",getValue(#{"bd.staff.Staff"}$,"id","user_id",userId())))

二、函数脚本

1、前端脚本

  // 卡单初始化
  function (event) {
    var viewModel = this;
    let user = cb.rest.AppContext.user;
    let mode = viewModel.getParams().mode;
    viewModel.on('afterLoadData',function(){
      //查询组织信息 赋值主组织
      debugger;
      if(mode.toLowerCase() === 'add') {
        let result = cb.rest.invokeFunction("GT102500AT53.backApi.queryOrgAndDept", {userId:user.userId},
        function(err, res) {},viewModel, {async:false});

        viewModel.get("org_id").setValue(result.result.orgId);
        viewModel.get("org_id_name").setValue(result.result.orgName);
      }
    })
  }

2、后端脚本

  let AbstractAPIHandler = require('AbstractAPIHandler');
    class MyAPIHandler extends AbstractAPIHandler {
    execute(request){
      var userId = request.userId;
      //通过用户ID查询员工信息
      let base_path = "https://yonbip.diwork.com/iuap-api-gateway/yonbip/digitalModel/staffQry/getStaff";
      var body = {
          "userId": [
              userId
          ]
      };
      //请求数据
      let apiResponse = openLinker("post", base_path, "GT102500AT53", JSON.stringify(body));

      var result = JSON.parse(apiResponse);
      // throw new Error(apiResponsejaon);
      var queryCode = result.code;
      if (queryCode !== "200") {
          throw new Error('查询用户对应人员错误 ' + result.message);
      }
      var psndocid = result.data.data[0].id;
      var psndocname = result.data.data[0].name;
      var dept_id = result.data.data[0].dept_id;
      var dept_id_name = result.data.data[0].dept_id_name;
      var org_id = result.data.data[0].org_id;
      var org_id_name = result.data.data[0].org_id_name;

      return {
          "staffId": psndocid,
          "staffName": psndocname,
          "deptId": dept_id,
          "deptName": dept_id_name,
          "orgId": org_id,
          "orgName": org_id_name
      }
    }
  }
  exports({"entryPoint":MyAPIHandler});
Copyright © 用友 -【生态技术部】 2021 all right reserved,powered by Gitbook修订时间: 2022-09-05 16:29:48

results matching ""

    No results matching ""