在Sharepoint Designer的工作流编辑器中,如何获取工作流发起者的用户名?
时间:2020-03-06 14:42:07 来源:igfitidea点击:
我希望在Sharepoint Designer的工作流编辑器中检索工作流发起者的用户名/名称(即谁启动或者触发了工作流),这相对容易使用第三方产品(例如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>
解决方案
我认为这在开箱即用的SharePoint Designer中是不可能的。我们可能可以编写一个自定义动作来获取发起者,但是我完全不相信它会通过SPD工作流界面公开。
我们可能要做的最好的事情就是让创建或者修改列表中项目的用户,但这无法处理手动运行工作流的情况。
我可以考虑仅使用SPD来解决此问题的简单但不是非常复杂的解决方案。仅在工作流步骤中,在辅助列表(可能是一个任务列表,其中存储了工作流ID和itemId属性以供回溯)中创建一个测试项目,然后在工作流中对该列表进行查找以查看谁是该项目的创建者,值将是当前的工作流发起者。