【利用Flow每天获取Flow的状态及运行记录】大鹏一日同风起,扶摇直上九万里。这篇文章主要讲述利用Flow每天获取Flow的状态及运行记录相关的知识,希望能为你提供帮助。
我是微软Dynamics 365 &
Power Platform方面的工程师/顾问罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面的微软最有价值专家(Microsoft MVP),欢迎关注我的微信公众号 MSFTDynamics365erLuoYong ,回复464或者20220307可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!
前面的文章
??通过Custom Connector获取flow的运行记录???
讲述了通过flow获取flow的运行记录,这篇文章扩展下,我们做个配置表出来,配置监控哪些flow,以及实际将flow的运行记录主要信息放到Microsoft Dataverse中。
首先我简历一个配置Flow监控的表,状态为可用的就是要监控的,停用的记录就不再监控,这样利用标准的启用/停用功能来配置是否监控。还做了个Flow运行记录表,用来存储flow运行记录的主要信息。
然后建立一个环境变量 (了解环境变量可以参考我的博文 ??在Power Apps中使用环境变量?? )来存储一些配置性的东西,如下:
保存后打开这个环境变量,设置它的默认值(Default Value)如下:
"EnvironmentId":"6cd1dc1a-56f7-4090-ba7c-e06c4055c81a",
"DefaultSolutionId":"fd140aaf-4df4-11dd-bd17-0019b9312238",
"AlertEmails":"luo.yong@hotmail.com",
"ViewFlowLink":"https://asia.flow.microsoft.com/manage/environments/0/solutions/1/flows/2/",
"ViewFlowRunHistoryLink":"https://asia.flow.microsoft.com/manage/environments/0/solutions/1/flows/2/runs/3"
然后我创建一个Custom API来批量创建和设置Flow设置记录:
这个Custom API我使用的代码如下:
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
namespace D365.Plugins
public class CustomAPIUpsertFlowMonitorSettings : IPlugin
public void Execute(IServiceProvider serviceProvider)
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService adminOrgSvc = serviceFactory.CreateOrganizationService(null);
var flowSetting = GetEnvironmentVariableValue("ly_FlowMonitorSetting", adminOrgSvc, tracingService);
if (string.IsNullOrEmpty(flowSetting))
throw new InvalidPluginExecutionException("名称为ly_FlowMonitorSetting的环境变量没有设置,请联系系统管理员!");
var flowSettingDic = DeserializeDictionary(flowSetting);
if (!flowSettingDic.ContainsKey("EnvironmentId") || !flowSettingDic.ContainsKey("DefaultSolutionId") || !flowSettingDic.ContainsKey("AlertEmails") || !flowSettingDic.ContainsKey("ViewFlowLink") || !flowSettingDic.ContainsKey("ViewFlowRunHistoryLink"))
throw new InvalidPluginExecutionException("名称为ly_FlowMonitorSetting的环境变量设置有问题,部分元素没有设置,请联系系统管理员!");
var queryWorkflow = new QueryExpression("workflow");
queryWorkflow.NoLock = true;
queryWorkflow.ColumnSet = new ColumnSet("name", "workflowidunique", "statecode");
queryWorkflow.Criteria.AddCondition("category", ConditionOperator.Equal, 5);
queryWorkflow.Criteria.AddCondition("type", ConditionOperator.Equal, 1);
var workflowEc = adminOrgSvc.RetrieveMultiple(queryWorkflow);
QueryExpression qe;
EntityCollection ec;
foreach (var workflowEntity in workflowEc.Entities)
qe = new QueryExpression("ly_flowmonitorsetting");
qe.TopCount = 1;
qe.NoLock = true;
qe.ColumnSet.AddColumn("ly_flowmonitorsettingid");
qe.Criteria.AddCondition("ly_workflowidunique", ConditionOperator.Equal, workflowEntity.GetAttributeValue<
Guid>
("workflowidunique").ToString());
ec = adminOrgSvc.RetrieveMultiple(qe);
if (ec.Entities.Any())
var updateEntity = new Entity("ly_flowmonitorsetting", ec.Entities[0].Id);
updateEntity["ly_flowname"] = workflowEntity.GetAttributeValue<
string>
("name");
updateEntity["ly_isturnon"] = workflowEntity.GetAttributeValue<
OptionSetValue>
("statecode").Value =https://www.songbingjia.com/android/= 0 ? false : true;
adminOrgSvc.Update(updateEntity);
else
var createEntity = new Entity("ly_flowmonitorsetting");
createEntity["ly_name"] = workflowEntity.GetAttributeValue<
string>
("name");
createEntity["ly_isturnon"] = workflowEntity.GetAttributeValue<
OptionSetValue>
("statecode").Value =https://www.songbingjia.com/android/= 0 ? false : true;
createEntity["ly_workflowidunique"] = workflowEntity.GetAttributeValue<
Guid>
("workflowidunique").ToString();
createEntity["ly_flowname"] = workflowEntity.GetAttributeValue<
string>
("name");
createEntity["ly_viewflowlink"] = string.Format(flowSettingDic["ViewFlowLink"], flowSettingDic["EnvironmentId"], flowSettingDic["DefaultSolutionId"], workflowEntity.GetAttributeValue<
Guid>
("workflowidunique").ToString());
adminOrgSvc.Create(createEntity);
private
推荐阅读
- Docker数据管理与镜像的创建
- Linux离线安装Awx
- MySQL高级(进阶) SQL 语句一
- AD活动目录FSMO五大角色
- Docker学习笔记01
- 企业微信报警提示, /usr/bin/python: bad interpreter: No such file or directory
- MySQL高级(进阶) SQL 语句二
- Docker 数据管理(数据卷容器/镜像创建)
- Docker 搭建本地私有仓库