更改工作流程的所有者

发布于 2024-12-23 06:53:48 字数 791 浏览 3 评论 0原文

我正在创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2024-12-30 06:53:48

您无法通过更新来更改记录的所有者。您必须使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文