微软 Power Apps model drven app 模型驱动应用使用Plugin插件实现业务流程跳转阶段功能

微软 Power Apps model drven app 模型驱动应用使用Plugin插件实现业务流程跳转阶段功能

模型驱动应用使用插件实现跳转业务流程阶段跳转功能

在实际操作中总会遇到使用业务流程的需求,那么如何使用plugin实现跳转阶段的功能呢

需求背景是主表上有业务流程,子表上有一个选项集字段,选项集字段包含所有的业务流程阶段,在更新子表的选项集时主表的业务流程阶段也需要同步跳转。

由于创建和更新查询不同,所以可以写两个plugin 也可以写在一个中使用message去控制

csharp 复制代码
//创建时执行
if (Context.MessageName=="Create")
   {
       //查询刚刚触发创建的业务流程(业务流程实体)
       string strXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
              strXml += "<entity name='new_start'>";
              strXml += "<attribute name='businessprocessflowinstanceid' />";
              strXml += "<attribute name='bpf_name' />";
              strXml += "<attribute name='createdon' />";
              strXml += "<attribute name='bpf_new_salesopportunityid' />";
              strXml += "<attribute name='activestageid' />";
              strXml += "<attribute name='statecode' />";
              strXml += "<attribute name='statuscode' />";
              strXml += "<attribute name='createdby' />";
              strXml += "<attribute name='processid' />";
              strXml += "<order attribute='bpf_name' descending='false' />";
              strXml += "<filter type='and'>";
              strXml += "<condition attribute='businessprocessflowinstanceid' operator='eq' value='" + target.Id + "' />";
              strXml += "</filter>";
              strXml += "</entity>";
              strXml += "</fetch>";
              EntityCollection start = Service.RetrieveMultiple(new FetchExpression(strXml));
              if (start.Entities.Count > 0)
              {
                   Entity Entitytag = Service.Retrieve("new_salesopportunity", start.Entities[0].GetAttributeValue<EntityReference>("bpf_new_salesopportunityid").Id, new ColumnSet("new_phase", "new_businesstype"));
                   //如果包含阶段
                   if (Entitytag.Contains("new_phase"))
                   {
                            //查询需要跳转的阶段(流程阶段值实体)
                            string StageFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
                            StageFetch += "<entity name='processstage'>";
                            StageFetch += "<attribute name='processstageid' />";
                            StageFetch += "<attribute name='processid' />";
                            StageFetch += "<attribute name='stagename' />";
                            StageFetch += "<order attribute='stagename' descending='false' />";
                            StageFetch += "<filter type='and'>";
                            //这里是阶段id 也可以再查一次,这里不大严谨就直接放入了id
                            StageFetch += "<condition attribute='processid' operator='eq' value='{5674a97c-e2d7-4ae6-9dfa-15a8ad0fa340}' />";
                            //根据选项集的name搜索我们要跳转的阶段
                            StageFetch += "<condition attribute='stagename' operator='eq' value='" + Entitytag.GetAttributeValue<EntityReference>("new_phase").Name + "' />";
                            StageFetch += "</filter>";
                            StageFetch += "</entity>";
                            StageFetch += "</fetch>";
                            EntityCollection steges = Service.RetrieveMultiple(new FetchExpression(StageFetch));
                            if (steges.Entities.Count > 0)
                            {
                                //修改流程阶段
                                Entity getProcess = new Entity("new_start");
                                getProcess.Id = start.Entities[0].Id;
                                getProcess["activestageid"] = new EntityReference("processstage", steges.Entities[0].Id);
                                //更新流程阶段
                                Service.Update(getProcess);
                            }
                        }
                    }
                }
                

下面是update时执行,我把它拆开了

csharp 复制代码
else if (Context.MessageName == "Update")
        {
            Entity Entitytag = Service.Retrieve("new_salesopportunity", target.Id, new ColumnSet("new_phase", "new_businesstype"));
            if (target.Contains("new_phase"))
               {
                  //查询需要跳转的阶段(update时候直接查询流程阶段实体即可)
                 string StageFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
                        StageFetch += "<entity name='processstage'>";
                        StageFetch += "<attribute name='processstageid' />";
                        StageFetch += "<attribute name='processid' />";
                        StageFetch += "<attribute name='stagename' />";
                        StageFetch += "<order attribute='stagename' descending='false' />";
                        StageFetch += "<filter type='and'>";
                        StageFetch += "<condition attribute='processid' operator='eq' value='{5674a97c-e2d7-4ae6-9dfa-15a8ad0fa340}' />";
                        StageFetch += "<condition attribute='stagename' operator='eq' value='" + Entitytag.GetAttributeValue<EntityReference>("new_phase").Name + "' />";
                        StageFetch += "</filter>";
                        StageFetch += "</entity>";
                        StageFetch += "</fetch>";
                        EntityCollection steges = Service.RetrieveMultiple(new FetchExpression(StageFetch));
                        if (steges.Entities.Count > 0)
                        {
                            //查询触发创建的业务流程
                            string strXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
                            strXml += "<entity name='new_start'>";
                            strXml += "<attribute name='businessprocessflowinstanceid' />";
                            strXml += "<attribute name='bpf_name' />";
                            strXml += "<attribute name='createdon' />";
                            strXml += "<attribute name='bpf_new_salesopportunityid' />";
                            strXml += "<attribute name='activestageid' />";
                            strXml += "<attribute name='statecode' />";
                            strXml += "<attribute name='statuscode' />";
                            strXml += "<attribute name='createdby' />";
                            strXml += "<attribute name='processid' />";
                            strXml += "<order attribute='bpf_name' descending='false' />";
                            strXml += "<filter type='and'>";
                            strXml += "<condition attribute='bpf_new_salesopportunityid' operator='eq' value='" + target.Id + "' />";
                            strXml += "</filter>";
                            strXml += "</entity>";
                            strXml += "</fetch>";
                            EntityCollection start = Service.RetrieveMultiple(new FetchExpression(strXml));
                            if (start.Entities.Count>0)
                            {
                                //修改流程阶段
                                Entity getProcess = new Entity("new_start");
                                getProcess.Id = start.Entities[0].Id;
                                getProcess["activestageid"] = new EntityReference("processstage", steges.Entities[0].Id);
                                //更新流程阶段
                                Service.Update(getProcess);
                            }
                        }
                    }
                }

然后把这个plugin注册在子表上的create 和 update 即可,这里看具体的业务需求实现

当然如果觉得plugin麻烦也可以同理写一个前端的js来实现。

感谢大佬指正 小Monkey
如果你觉得有用的话,就留个赞吧!蟹蟹

相关推荐
齐 飞几秒前
MongoDB笔记01-概念与安装
前端·数据库·笔记·后端·mongodb
云空1 分钟前
《Python 与 SQLite:强大的数据库组合》
数据库·python·sqlite
暮毅6 分钟前
10.Node.js连接MongoDb
数据库·mongodb·node.js
wowocpp9 分钟前
ubuntu 22.04 server 格式化 磁盘 为 ext4 并 自动挂载 LTS
服务器·数据库·ubuntu
成富31 分钟前
文本转SQL(Text-to-SQL),场景介绍与 Spring AI 实现
数据库·人工智能·sql·spring·oracle
songqq2732 分钟前
SQL题:使用hive查询各类型专利top 10申请人,以及对应的专利申请数
数据库·sql
计算机学长felix36 分钟前
基于SpringBoot的“校园交友网站”的设计与实现(源码+数据库+文档+PPT)
数据库·spring boot·毕业设计·交友
小码的头发丝、1 小时前
Django中ListView 和 DetailView类的区别
数据库·python·django
Karoku0662 小时前
【企业级分布式系统】Zabbix监控系统与部署安装
运维·服务器·数据库·redis·mysql·zabbix
周全全2 小时前
MySQL报错解决:The user specified as a definer (‘root‘@‘%‘) does not exist
android·数据库·mysql