6

在 Sharepoint 设计器的工作流编辑器中,我希望检索工作流发起者的用户名/名称(即谁启动它或触发了工作流) - 这相对容易使用 3rd 方产品,如 Nintex Workflow 2007(我会使用类似 {Common:Initiator}) - 但我似乎无法找到任何开箱即用的方法来使用共享点设计器和 MOSS 2007 做到这一点。

更新

OOTB 看起来并不支持这个相当明显的功能,所以我最终编写了一个自定义活动(如其中一个答案所建议的那样)。我在这里列出了活动代码以供参考,尽管我怀疑博客上可能有一些这样的实例,因为它是一个非常简单的解决方案:

public partial class LookupInitiatorInfo : Activity
{
    public static DependencyProperty __ActivationPropertiesProperty =
        DependencyProperty.Register("__ActivationProperties",
        typeof(Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties),
        typeof(LookupInitiatorInfo));

    public static DependencyProperty __ContextProperty =
        DependencyProperty.Register("__Context", typeof (WorkflowContext),
        typeof (LookupInitiatorInfo));

    public static DependencyProperty PropertyValueVariableProperty =
        DependencyProperty.Register("PropertyValueVariable", typeof (string),    
        typeof(LookupInitiatorInfo));

    public static DependencyProperty UserPropertyProperty = 
        DependencyProperty.Register("UserProperty", typeof (string),
        typeof (LookupInitiatorInfo));

    public LookupInitiatorInfo()
    {
        InitializeComponent();
    }

    [Description("ActivationProperties")]
    [ValidationOption(ValidationOption.Required)]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties __ActivationProperties
    {
        get { return ((Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties)(base.GetValue(__ActivationPropertiesProperty))); }
        set { base.SetValue(__ActivationPropertiesProperty, value); }
    }

    [Description("Context")]
    [ValidationOption(ValidationOption.Required)]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public WorkflowContext __Context
    {
        get { return ((WorkflowContext)(base.GetValue(__ContextProperty))); }
        set { base.SetValue(__ContextProperty, value); }
    }

    [Description("UserProperty")]
    [ValidationOption(ValidationOption.Required)]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string UserProperty
    {
        get { return ((string) (base.GetValue(UserPropertyProperty))); }
        set { base.SetValue(UserPropertyProperty, value); }
    }

    [Description("PropertyValueVariable")]
    [ValidationOption(ValidationOption.Required)]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string PropertyValueVariable
    {
        get { return ((string) (base.GetValue(PropertyValueVariableProperty))); }
        set { base.SetValue(PropertyValueVariableProperty, value); }
    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        // value values for the UserProperty (in most cases you
        // would use LoginName or Name)

        //Sid
        //ID
        //LoginName
        //Name
        //IsDomainGroup
        //Email
        //RawSid
        //Notes

        try
        {
            string err = string.Empty;

            if (__ActivationProperties == null)
            {
                err = "__ActivationProperties was null";
            }
            else
            {
                SPUser user = __ActivationProperties.OriginatorUser;

                if (user != null && UserProperty != null)
                {
                    PropertyInfo property = typeof (SPUser).GetProperty(UserProperty);
                    if (property != null)
                    {
                        object value = property.GetValue(user, null);
                        PropertyValueVariable = (value != null) ? value.ToString() : "";
                    }
                    else
                    {
                        err = string.Format("no property found with the name \"{0}\"", UserProperty);
                    }
                }
                else
                {
                    err = "__ActivationProperties.OriginatorUser was null";
                }
            }
            if (!string.IsNullOrEmpty(err))
                Common.LogExceptionToWorkflowHistory(new ArgumentOutOfRangeException(err), executionContext,
                                                     WorkflowInstanceId);
        }
        catch (Exception e)
        {
            Common.LogExceptionToWorkflowHistory(e, executionContext, WorkflowInstanceId);
        }

        return ActivityExecutionStatus.Closed;
    }
}

然后将其与以下 .action xml 文件连接起来:

<?xml version="1.0" encoding="utf-8"?>
<WorkflowInfo Language="en-us">
<Actions>
    <Action Name="Lookup initiator user property"
 ClassName="XXX.ActivityLibrary.LookupInitiatorInfo"
 Assembly="XXX.ActivityLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXX"
 AppliesTo="all"
 Category="WormaldWorkflow Custom Actions">
        <RuleDesigner Sentence="Lookup initating users property named %1 and store in %2">
            <FieldBind Field="UserProperty" DesignerType="TextArea" Id="1" Text="LoginName" />              
            <FieldBind Field="PropertyValueVariable" DesignerType="ParameterNames" Text="variable" Id="2"/>
        </RuleDesigner>
        <Parameters>
            <Parameter Name="__Context" Type="Microsoft.Sharepoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In"/>
            <Parameter Name="__ActivationProperties" Type="Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties, Microsoft.SharePoint" Direction="In"/>
            <Parameter Name="UserProperty" Type="System.String, mscorlib" Direction="In" />
            <Parameter Name="PropertyValueVariable" Type="System.String, mscorlib" Direction="Out" />
        </Parameters>
    </Action>
</Actions>
</WorkflowInfo>
4

4 回答 4

5

对于那些通过谷歌搜索本文并现在使用 SharePoint 2010 的用户,SharePoint Designer 中现在支持工作流启动器变量 OOTB。

数据源将是“工作流上下文”,该字段当然是“发起者”,您可以选择将其返回为“显示名称”、“电子邮件”、“登录名”或“用户 ID 号”

于 2011-02-02T16:25:37.140 回答
2

我认为这在 SharePoint Designer 中是不可能做到的。您可能可以编写一个自定义操作来获取发起者,但我认为它根本不会通过 SPD 工作流界面公开。

您可能做的最好的事情是获取在列表中创建或修改项目的用户,但这不会处理手动运行工作流的情况。

于 2008-09-25T07:46:50.360 回答
1

我可以通过仅使用 SPD 来考虑一个简单但不是非常复杂的解决方案。只需在工作流步骤中在辅助列表中创建一个测试项目(可能是一个任务列表,其中存储了 workflowId 和 itemId 属性以供参考),然后在您的工作流中对该列表进行查找以查看谁是该项目的创建者,即value 将是当前的工作流发起者。

于 2009-11-19T00:29:49.353 回答
0

自定义活动解决方案仅在您使用 moss 时才有效,如果您只有 wss 3.0,您可以在工作流程中多放一步并设置包含任何信息的自定义评论字段,这会使最后修改的人更改并变得相同作为工作流发起者,您可以使用 ModifiedBy 字段来做出您需要的任何决定。

于 2011-09-13T15:43:49.230 回答