SharePoint デザイナーのワークフロー エディターで、ワークフロー開始者のユーザー名を取得するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/131238

質問

Sharepoint デザイナーのワークフロー エディターで、ワークフロー開始者のユーザー名/名前を取得したいと考えています (つまり、誰がワークフローを開始したのか、またはワークフローをトリガーしたのか) - これは、Nintex Workflow 2007 などのサードパーティ製品を使用すると比較的簡単に実行できます (ここでは、{Common:Initiator} などを使用します) - しかし、方法が見つからないようです共有ポイント デザイナーと MOSS 2007 を使用してこれを行うには、ボックスの

アップデート

このかなり明白な機能が OOTB でサポートされているようには見えないため、(回答の 1 つで示唆されているように) カスタム アクティビティを作成することになりました。参考のためにここにアクティビティ コードをリストしました。ただし、これは非常に簡単な解決策であるため、ブログ上でおそらくこの例がいくつか出回っていると思います。

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 ワークフロー インターフェイスを通じて公開されるとはまったく考えられません。

おそらくできる最善の方法は、リスト内の項目を作成または変更したユーザーを取得することですが、これではワークフローが手動で実行された場合は処理できません。

他のヒント

Google でこの記事を参照し、SharePoint 2010 を使用している人のために説明すると、SharePoint Designer ではワークフロー イニシエーター変数が OOTB でサポートされるようになりました。

データソースは「ワークフロー コンテキスト」、フィールドはもちろん「イニシエーター」で、「表示名」、「電子メール」、「ログイン名」、または「ユーザー ID 番号」として返すことを選択できます。

これについては、SPD だけを使用することで、シンプルではありますが、あまり洗練されていない解決策を考えることができます。ワークフローのステップ内で、セカンダリ リスト (おそらく、再参照用の workflowId プロパティと itemId プロパティを保存するタスク リスト) にテスト項目を作成し、そのリストのワークフローで検索を実行して、その項目の作成者が誰であるかを確認します。値は現在のワークフロー開始者になります。

カスタム アクティビティ ソリューションは、moss を使用している場合にのみ機能します。wss 3.0 のみを使用している場合は、ワークフローにもう 1 つのステップを追加して、任意の情報を含むカスタム コメント フィールドを設定できます。これにより、最後に変更されたユーザーが変更され、同じになります。ワークフローの開始者としての場合は、ModifiedBy フィールドを使用して必要な決定を下すことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top