🚀 Dynamics 365 Finance + Power Automate 自动化凭证审核
📑 目录
- [🚀 Dynamics 365 Finance + Power Automate 自动化凭证审核](#🚀 Dynamics 365 Finance + Power Automate 自动化凭证审核)
-
- [1. 依赖 🔧](#1. 依赖 🔧)
- [2. 目标 🎯](#2. 目标 🎯)
- [3. 系统架构 🏗️](#3. 系统架构 🏗️)
- [4. 凭证审批全流程 🛠️](#4. 凭证审批全流程 🛠️)
-
- [4.1 在 D365 Finance 中配置工作流 ⚙️](#4.1 在 D365 Finance 中配置工作流 ⚙️)
- [4.2 Power Automate 流程配置 🔄](#4.2 Power Automate 流程配置 🔄)
- [4.3 DocuSign 集成示例 ✒️](#4.3 DocuSign 集成示例 ✒️)
-
- [4.3.1 JWT 验证与令牌获取 🔑](#4.3.1 JWT 验证与令牌获取 🔑)
- [4.3.2 创建 Envelope 📄](#4.3.2 创建 Envelope 📄)
- [4.3.3 Webhook 回调与下载签名文件 🔄](#4.3.3 Webhook 回调与下载签名文件 🔄)
- [5. 异常控制与统一补偿 🔁](#5. 异常控制与统一补偿 🔁)
- [6. 安全与性能最佳实践 🔒](#6. 安全与性能最佳实践 🔒)
- [7. Power Platform Solution 化部署 🗂️](#7. Power Platform Solution 化部署 🗂️)
- [8. 可复现部署脚本示例(Bicep) 📝](#8. 可复现部署脚本示例(Bicep) 📝)
- [9. 监控与可视化 📊](#9. 监控与可视化 📊)
1. 依赖 🔧
- Dynamics 365 Finance: 10.0.x
- Power Automate: Dataverse v2 连接器
- DocuSign API : v2.1, scope=
signature
- Azure Key Vault: Managed Identity 支持
2. 目标 🎯
- ⚙️ 自定义多级审批阶段与条件分支
- 📬 基于 Power Automate 的异常触发、动态通知与重试
- 🔐 DocuSign/Adobe Sign 电子签章集成(v2.1 API + JWT)
- ♻️ 流程闭环:超时补偿、统一异常处理、自动归档、日志审计
- 📈 可扩展监控与可视化(Power BI、Log Analytics)
3. 系统架构 🏗️
通知 签章服务 自动化层 企业系统 Microsoft Teams Outlook 邮件 DocuSign API v2.1 Power Automate
Dataverse v2 Azure Key Vault D365 Finance 10.0.x SharePoint 存储 Power BI 仪表板
4. 凭证审批全流程 🛠️
4.1 在 D365 Finance 中配置工作流 ⚙️
-
登录 Dynamics 365 Finance 10.0.x → 模块 > 凭证工作流 > 新建工作流。
-
添加三个"审批任务"节点,并在 条件分支 中配置:
textExpression: JournalAmount >= 100000 // 单位为基础货币,多币种场景下请乘以对应汇率字段。
-
指定节点流转:
- < 10,000 → "直接通过" ✅
- ≥ 10,000 且 < 100,000 → "财务经理审批" 👥
- ≥ 100,000 → "CFO 审批 + 调用签章" ✒️
4.2 Power Automate 流程配置 🔄
-
触发器
- 类型:当 Dynamics 365 Finance 中的记录被更新(Dataverse v2)
- 表名:
JournalHeader
- 频率:默认 5 分钟 ⏱️
-
初始化变量
yamlAction: Initialize variable Name: approverEmail Type: String Value: triggerOutputs()?['body/ApproverEmail']
-
条件控制
expression@equals(triggerOutputs()?['body/ApprovalStatus'], 'Rejected')
- Option Set 场景下请改为
body/statuscode
。⚠️
- Option Set 场景下请改为
-
并发与重试
-
并行度:在"Settings"中将并行度设为 1。
-
重试策略 (UI "Settings" → "Retry Policy"):
json{ "type": "fixed", "interval": "PT10S", "count": 3 }
-
-
流程:
D365 PowerAutomate DocuSign TM SP OL 记录更新触发 条件检查 (Rejected?) Teams 通知 更新状态 'NeedReview' 日志存 SharePoint Create Envelope alt [Rejected] [Approved] Webhook 回调 附加签名 PDF 存档 发送邮件 D365 PowerAutomate DocuSign TM SP OL
4.3 DocuSign 集成示例 ✒️
4.3.1 JWT 验证与令牌获取 🔑
-
使用 Postman 或脚本执行 JWT Authorization Flow:
bashPOST https://account-d.docusign.com/oauth/token Content-Type: application/x-www-form-urlencoded grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer& assertion=<Base64-Encoded-JWT>
-
返回字段
access_token
,后续 API 请求携带Authorization: Bearer <access_token>
。
4.3.2 创建 Envelope 📄
json
POST https://demo.docusign.net/restapi/v2.1/accounts/{accountId}/envelopes
Authorization: Bearer <access_token>
Content-Type: application/json
{
"emailSubject": "请签署会计凭证",
"status": "sent",
"documents": [
{
"documentBase64": "<Base64PDF>",
"name": "Voucher.pdf",
"fileExtension": "pdf",
"documentId": "1"
}
],
"recipients": {
"signers": [
{
"email": "[email protected]",
"name": "财务经理",
"recipientId": "1",
"routingOrder": "1"
}
]
}
}
4.3.3 Webhook 回调与下载签名文件 🔄
-
在 Power Automate 中添加 "When a HTTP request is received",粘贴 DocuSign Webhook JSON Schema,并在"高级选项"开启
X-DocuSign-Signature
验证。 -
成功回调后调用:
httpGET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents/combined Authorization: Bearer <access_token>
-
将返回 PDF 二进制通过 PATCH 更新到 D365:
httpPATCH https://<your-d365>.api/data/v9.0/journalHeaders({id})/YourFileField Content-Type: application/json { "[email protected]": "<BlobContent>" }
5. 异常控制与统一补偿 🔁
异常处理 (Scope) 主流程 failed succeeded Send Admin Alert 🚨 HasFailed? Log to Analytics 📝 审批逻辑 Trigger 后续归档
- 使用 Scope + Configure run after 捕获所有失败分支,统一发送告警并落日志。
- 审批超时 :采用 "Do until" + "Delay" 每 6 小时检查
Pending
,超时发送重分配通知。
6. 安全与性能最佳实践 🔒
-
Key Vault 访问 :
- 在 Azure Key Vault → Access policies 中,为 Power Automate 服务主体 授予
Get Secret
权限。
- 在 Azure Key Vault → Access policies 中,为 Power Automate 服务主体 授予
-
并发控制:流程并行度设为 1;高峰期可拆分子流程分流。
-
审计日志 :
- 在 Power Automate → "Diagnostic settings" 将所有运行日志推送至 Azure Log Analytics。
json{ "logs": [ { "category": "WorkflowRuntime", "enabled": true } ], "destination": { "workspaceId": "/subscriptions/.../resourceGroups/.../providers/Microsoft.OperationalInsights/workspaces/..." } }
7. Power Platform Solution 化部署 🗂️
-
在 Power Apps Portal 中创建 Solution,将自定义 Flow、环境变量、连接器绑定一同打包。
-
导出为
.zip
,并在目标环境导入,保证 DEV/TEST/PROD 环境一致性。 -
可通过 PowerShell 脚本调用 Power Platform CLI:
bashpac solution import --path ./MySolution.zip --environment <ENVIRONMENT_URL>
8. 可复现部署脚本示例(Bicep) 📝
bicep
targetScope = 'resourceGroup'
resource voucherFlow 'Microsoft.Logic/workflows@2019-05-01' = {
name: 'VoucherApprovalFlow'
properties: {
definition: json(loadTextContent('voucher-flow-definition.json'))
parameters: {}
integrationServiceEnvironment: null
}
}
确保
voucher-flow-definition.json
与 Bicep 文件同目录,CI/CD 管道中一并推送。
9. 监控与可视化 📊
-
Log Analytics → Power BI
-
Power BI Desktop 中新增数据源:Azure Log Analytics,示例 DAX:
daxAverageApprovalTime = AVERAGEX( FILTER( 'WorkflowRuns', 'WorkflowRuns'[Status] = "Succeeded" ), 'WorkflowRuns'[DurationSeconds] )
-
-
实施仪表盘:展示平均审批时长、超时率、失败率,为持续优化提供依据。