
# 创建首条审批单据同步流
1. 在SAP B1要同步的单据主表添加四个自定义字段： 
   U_BMID： 记录钉钉审批发起人员的部门ID，需要查询钉钉系统维护在SAP表中
   钉钉发起人部门ID查询方式：
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434034.png)
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522793771.png)
   U_UserID： 记录钉钉审批发起人的人员ID，需要查询钉钉系统维护在SAP表中
   钉钉发起人用户ID查询方式：
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594002.png)
   U_ISSYN：记录单据的同步状态，默认值为N
   U_instanceID： 记录审批实例ID，注意字段长度设置要足够，无需手动维护字段值
   
   
   
2. 在钉钉创建审批表单 
   登录钉钉，工作台-应用管理，选择"OA审批"应用，进入
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522793763.png)
   
   创建一个新表单
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594008.png)
   选择流程表单
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434048.png)
   基础配置中，表单名称，见名知义，分组任意选择，记录底部表单ID
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434042.png)
   
   表单设计中，按需配置所需字段（**当前只支持单行输入框、明细/表格、数字输入框，不支持时间和金额类字段，用单行输入框和数字输入框代替**）
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594024.png)
   
   表单审批流程，按需配置
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490593988.png)
   发布表单，
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522633803.png)
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522793779.png)
   
   
   
3. 新建钉钉应用 
   登录钉钉开放平台，
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522633781.png)
   创建应用，
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594026.png)
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594018.png)
   
   
   
   
   
4. 进入我的流模板，选择"SAP同步钉钉审批模板-基于SQLQUERY"同步流模板，选择"创建流" 
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002498847094.png)
   
   
5. 配置定时任务同步周期，默认1分钟，可以修改，配置完下一步 
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434032.png)
   
   
6. 配置主表SQL，以及sql字段和钉钉表单主表字段的映射关系 
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522793765.png)
   配置注意事项：
   - sql语句必须有一个与子表sql语句的关联字段，一般是主键字段，如上图中DocEntry
   
   - sql语句中必须查出钉钉发起人ID字段和部门ID字段，即: U_UserID、U_BMID
   
   - 下方关联配置中，左边的字段会自动根据sql语句解析，右边填写对应的钉钉表单字段
   
   
   
   
   
7. 配置子表SQL，以及sql字段和钉钉子表字段的映射关系， 
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594010.png)
   下一步
   
   
8. 进入之前钉钉创建的应用中，获取钉钉AppKey和AppSecret， 
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522793769.png)
   创建钉钉连接
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002530527897.png)
   
   填入并保存
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002530450361.png)
   
   
9. 创建SAP service layer连接 
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002530530771.png)
   输入Service layer访问地址（**根据具体项目填值，默认值一定要修改**）、数据库、用户名、密码、语言等信息，创建连接
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002530451279.png)
   创建后其余连接自动使用，下一步
   ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002530532749.png)
   
   
10. 完成相关配置，包括单据类型、SAP主表主键字段、SAP主键字段类型、SAP对应钉钉提交人的字段名、SAP对应钉钉部门提交人ID、钉钉审批表单的ID等信息 
    **单据类型**，标准审批单据选择草稿单，正式单据按需选择，自定义单据编辑备选项添加，
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490593990.png)
    **主键字段**，用于主子表关联，与前面sql查询使用的一致
    
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522793737.png)
    **SAP主键字段类型**，根据主键类型是数值还是字符串自行选择
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002522633783.png)
    **c_userid、deptID**，填写sap中配置的表示钉钉发起人ID和发起人部门ID的字段U_UserID，U_instanceID
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434064.png)
    **钉钉审批表单ID**，创建的钉钉表单的ID
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434038.png)
    下一步
    
    
    
11. 创建 
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434018.png)
    
    
12. 配置SqlQuery子流 
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002498853922.png)
    下一步
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002498855244.png)
    下一步
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490594028.png)
    更新
    ![](https://support.huaweicloud.com/bestpractice-sparkpack/zh-cn_image_0000002490434060.png)
    
    
 
