在sharepoint designer的工作流编辑器中,如何获取工作流启动器用户名?

时间:2008-09-25 02:56:52

标签: sharepoint workflow workflow-foundation sharepoint-designer workflow-activity

在Sharepoint设计器的工作流程编辑器中,我希望检索工作流程启动器的用户名/名称(即谁将其踢掉或触发工作流程) - 使用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 个答案:

答案 0 :(得分:5)

对于那些浏览本文并且现在正在使用SharePoint 2010的用户,现在在SharePoint Designer中支持工作流启动器变量OOTB。

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

答案 1 :(得分:2)

我不认为这可以在SharePoint Designer中开箱即用。您可以编写一个自定义操作来获取创建者,但我不相信它会通过SPD工作流界面公开。

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

答案 2 :(得分:1)

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

答案 3 :(得分:0)

自定义活动解决方案仅在您使用moss时才有效,如果您只有wss 3.0,您可以在工作流程中多放一步并设置包含任何信息的自定义注释字段,这会使最后修改的人员更改并且与工作流程启动器相同,然后您可以使用ModifiedBy字段做出您需要的任何决定。