需求说明:

当一个 Entity 存在 Business Process Process 时,有时我们需要改变其状态,在之前写的博客有讲了可以通过 JavaScript 来实现,本篇就来讲一下如何通过 C# Plugin 来实现对 BPF 的 abandon( abandon 后的 BPF 会变成灰色,BPF 里的  Stages 变成不可编辑,不能点击上一步和下一步,也不能 Set Active;如果想要使 Steps 也不可编辑,可通过 JavaScript 控制)。

解决方案:

通过 Solution 查看 Entities 组件时可以发现:在为一个 Entity 添加一个 Business Process Flow 的时候,实际上也是创建了一个新的 Entity(后面简称 BPF Entity),Entity 与 BPF Entity 之间的关系是 1:N。BPF Entity 中存在 Lookup 其 Primary Entity 的 Field,可以通过这个字段来查询当前 Entity 下的 BPF,之后改变其 State 和 Stauts 的值就可以将 BPF abandon 了。

Note:State -> statecode,Status -> statuscode,这两个字段都是 BPF Entity 的 Default Field,每个 Entity 都有的,表示状态,通过改变这两个字段的值来改变 Entity 的状态。

示例代码:

private void AbandonBPF(IOrganizationService service, Guid new_entity_id)
{
using (OrganizationServiceContext orgService = new OrganizationServiceContext(service))
{
var bpf_entity = (from _bpf_entity in orgService.CreateQuery<Entities.new_bpfentity>()
where _bpf_entity.bpf_new_entityid.Id == new_entity_id
select _bpf_entity).FirstOrDefault(); if (bpf_entity != null && bpf_entity.GetAttributeValue<OptionSetValue>("statecode").Value == )
{
//statecode = 1 and statuscode = 3 for abandon workflow
SetStateRequest setStateRequest = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = bpf_entity.BusinessProcessFlowInstanceId.Value,
LogicalName = Entities.new_bpfenity.EntityLogicalName,
},
State = new OptionSetValue(),
Status = new OptionSetValue()
};
service.Execute(setStateRequest);
}
}
}

Note:这里 new_entity 是 Entity name,new_bpfentity 是其对应 BPF Entity 的 name。

函数调用:

Entities.new_entity entity =  ((Entity)context.InputParameters["Target"]).ToEntity<Entities.new_entity>();
AbandonBPF(service, entity.id);

最新文章

  1. 2015微软MVP全球峰会见闻
  2. Android MVP模式 谷歌官方代码解读
  3. Android源码阅读-Filter过滤器
  4. Android中使用自定义View实现下载进度的显示
  5. LogViewer - 方便的日志查看工具
  6. MongoDB的学习--文档的插入、删除和更新
  7. RAC数据库迁移ASM磁盘组到其它存储
  8. iOS 10 消息推送(UserNotifications)秘籍总结(二)
  9. [Redux + Webpack] Hot reloading Redux Reducers with Webpack
  10. JavaScript apply函数小案例
  11. PHP学习之[第10讲]PHP 的 Mysql 数据库函数 (微型博客系统)II
  12. 使用solr报错,错误信息 include(SolrClient.php): failed to open stream: No such file or directory
  13. css3中动画animation的应用
  14. Hadoop-Impala学习笔记之入门
  15. RESTful摘要
  16. 两数之和,两数相加(leetcode)
  17. git从其他分支提取文件merge到当前分支
  18. 133、 Android 自动化测试(转载)
  19. sparse.coo_matrix()
  20. redis主从配置&lt;转&gt;

热门文章

  1. 2016蓝桥杯决赛C/C++A组第四题 路径之谜
  2. POJ 1039:Pipe 计算几何
  3. 18 ~ express ~ 前台分类导航展示 与 排序
  4. zabbix监控linux 以及监控mysql
  5. python虚拟环境配置(上)
  6. MVC学生管理系统-阶段III(删除学生信息)
  7. SourceTree - 对Git的使用
  8. 标准JAVA工程结构
  9. 阅读笔记--java内存模型原理
  10. jenkins+saltstack+pipeline 部署springcloud 多模块jar包