Workflow 以编程方式访问Sitecore用户';s工作箱

Workflow 以编程方式访问Sitecore用户';s工作箱,workflow,sitecore,Workflow,Sitecore,我想从C#访问用户的工作箱,这样我就可以循环访问其工作箱中的所有项目,并更新每个项目版本的工作流状态 我正在使用Sitecore 6.2.0(版本101105) 谢谢你的关注 编辑:以下代码需要在主上下文下运行—“从sitecore管理员内部”。如果您是从web上下文(站点上的一个页面)和context.Database“web”运行它,那么您需要将Sitecore.context.Database的所有实例替换为Factory.GetDatabase(“master”) 首先,您需要获取所有

我想从C#访问用户的工作箱,这样我就可以循环访问其工作箱中的所有项目,并更新每个项目版本的工作流状态

我正在使用Sitecore 6.2.0(版本101105)


谢谢你的关注

编辑:以下代码需要在主上下文下运行—“从sitecore管理员内部”。如果您是从web上下文(站点上的一个页面)和context.Database“web”运行它,那么您需要将Sitecore.context.Database的所有实例替换为Factory.GetDatabase(“master”)


首先,您需要获取所有工作流

Sitecore.Context.Database.WorkflowProvider.GetWorkflows();
然后,对于每个工作流,您需要获取所有状态:

workflow.GetStates();
然后,对于每个状态,您可以获得所有项目

var itemDataUris = workflow.GetItems(state);
GetItems返回数据URI的列表 因此,如果您当前与相关用户一起登录,您只需执行以下操作即可

foreach (var dataUri in itemDataUris)
{
    var item = Context.Database.GetItem(dataUri);
    //check if the item is null (if null the user doesn't have access to it
    if (item != null)
       usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
}
如果您以管理员身份运行,并且希望为其他用户获取该项目,则需要将上述代码包装在UserSwitcher中

Sitecore.Security.Accounts.UserSwitcher.Enter(Sitecore.Security.Accounts.User.FromName("sitecore\User", true));
foreach (var dataUri in itemDataUris)
    {
        var item = Context.Database.GetItem(dataUri);
        //check if the item is null (if null the user doesn't have access to it
        if (item != null)
           usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
    }
Sitecore.Security.Accounts.UserSwitcher.Exit();

希望有帮助

编辑:以下代码需要在主上下文下运行—“从sitecore管理员内部”。如果您是从web上下文(站点上的一个页面)和context.Database“web”运行它,那么您需要将Sitecore.context.Database的所有实例替换为Factory.GetDatabase(“master”)


首先,您需要获取所有工作流

Sitecore.Context.Database.WorkflowProvider.GetWorkflows();
然后,对于每个工作流,您需要获取所有状态:

workflow.GetStates();
然后,对于每个状态,您可以获得所有项目

var itemDataUris = workflow.GetItems(state);
GetItems返回数据URI的列表 因此,如果您当前与相关用户一起登录,您只需执行以下操作即可

foreach (var dataUri in itemDataUris)
{
    var item = Context.Database.GetItem(dataUri);
    //check if the item is null (if null the user doesn't have access to it
    if (item != null)
       usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
}
如果您以管理员身份运行,并且希望为其他用户获取该项目,则需要将上述代码包装在UserSwitcher中

Sitecore.Security.Accounts.UserSwitcher.Enter(Sitecore.Security.Accounts.User.FromName("sitecore\User", true));
foreach (var dataUri in itemDataUris)
    {
        var item = Context.Database.GetItem(dataUri);
        //check if the item is null (if null the user doesn't have access to it
        if (item != null)
           usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
    }
Sitecore.Security.Accounts.UserSwitcher.Exit();

希望有帮助

不确定代码运行的上下文或频率,但您是否可以使用用户工作箱中的RSS源?

不确定代码运行的上下文或频率,但您是否可以使用用户工作箱中的RSS源?

确保您没有尝试在web上下文中运行此代码。。。不行了,谢谢你,布莱恩。我会修改答案,确保答案是这样的。marto,非常感谢你的详细解释。这正是我需要的!如果有人有(完整的示例)此技术的工作演示代码,我无法将其用于我的sitecore开发实例6.4.1(修订版111003修补程序355338-3)。我需要为workbox/flow项访问创建一个API——谢谢,请确保您没有试图在web上下文中运行此代码。。。不行了,谢谢你,布莱恩。我会修改答案,确保答案是这样的。marto,非常感谢你的详细解释。这正是我需要的!如果有人有(完整的示例)此技术的工作演示代码,我无法将其用于我的sitecore开发实例6.4.1(修订版111003修补程序355338-3)。我需要为workbox/flow项访问制作一个API——谢谢