更改工作流程的所有者
我正在创建一个 linqpad 脚本,我想在其中实现以下目标:
1)将所有草稿和活动工作流程分配给我自己 2) 激活所有草稿工作流程
我的问题是,如果我尝试更改活动工作流程的所有者,则会收到一条错误消息,指出我无法更新工作流程,因为它处于活动状态。如果我尝试停用,则会错误地表明我不是所有者(因此不允许我)。这很令人困惑,因为我可以通过用户界面轻松地做到这一点。
我用来更新所有者的代码:
var systemUser =
var workflow = ...;
workflow.OwnerId = systemUser.ToEntityReference();
UpdateObject(workflow);
SaveChanges(); //exception: Cannot update a published workflow definition
我用来停用工作流程的代码:
var request = SetStateRequest {
EntityMoniker = workflow.ToEntityReference(),
State = new OptionSetValue(/*state value*/),
Status = new OptionSetValue(/* status value*/)
};
service.Execute(request); //exception: The workflow cannot be published or unpublished by someone who is not its owner
I am creating a linqpad script where I want to achieve the following:
1) Assign all draft and active workflows to myself
2) Activate all the draft workflows
My problem is that if I attempt to change the owner of an active workflow I get an error saying I cannot update the workflow because it's active. If I try deactivate then it errors saying I'm not the owner (hence I'm not allowed). It's confusing because I can easily do this via the UI.
The code I'm using to update owner:
var systemUser =
var workflow = ...;
workflow.OwnerId = systemUser.ToEntityReference();
UpdateObject(workflow);
SaveChanges(); //exception: Cannot update a published workflow definition
The code I'm using to deactivate workflow:
var request = SetStateRequest {
EntityMoniker = workflow.ToEntityReference(),
State = new OptionSetValue(/*state value*/),
Status = new OptionSetValue(/* status value*/)
};
service.Execute(request); //exception: The workflow cannot be published or unpublished by someone who is not its owner
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过更新来更改记录的所有者。您必须使用
AssignRequest
来更改所有者。请参阅我的回答:我可以吗使用 LINQ 更新联系人的所有者 ID?You can't change the owner of a record with an update. You have to use the
AssignRequest
to change the owner. See my answer at Can I update the owner id of a Contact using LINQ?