2

カスタム ソリューションを SharePoint 2010 にアップグレード中です。WorkflowCompletedイベント ハンドラを利用したかったのですが、イベント プロパティから関連するSPListItemを取得できないようです。

SPWorkflowEventProperties.ActivationPropertiesを使用してみましたが、これは常に null を返します ( WorkflowStartedイベント ハンドラーでも)。

ワークフロー イベント ハンドラー ( SPListItemSPWebSPSiteなど)からコンテキストを取得するにはどうすればよいですか?

4

3 に答える 3

2

同じものを見つけました。SPWorkflowEventProperties は、ほぼすべてが null であるため、実質的に役に立ちません。ステータス (承認済み、拒否済みなど) はわかりません。そして、最も重要なことは、どの項目が完了したかを (直接的に) 伝えないことです。うまくいけば、これは将来のバージョンで対処されるでしょう。その間、私は以下を使用しました:

public override void WorkflowCompleted(SPWorkflowEventProperties properties)
{
   using (SPSite site = new SPSite(properties.WebUrl))
   {
       using (SPWeb web = site.OpenWeb())
       {
           SPListItem task = GetApprovedTask(properties, web);
           SPListItem item = GetApprovedItem(web, task);
           if (null != item)
           {
               // TODO : process approved item
           }
       }
   }
}

private SPListItem GetApprovedItem(SPWeb web, SPListItem task)
{
   SPListItem item = null;
   if (null != task)
   {
       SPList list = web.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];
       item = list.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);
   }
   return item;
}

private SPListItem GetApprovedTask(SPWorkflowEventProperties properties, SPWeb web)
{
   SPListItem item = null;
   string caml = @"<Where><And><And><And><Eq><FieldRef Name='WorkflowOutcome' /><Value Type='Text'>Approved</Value></Eq><Eq><FieldRef Name='WorkflowInstanceID' /><Value Type='Guid'>{0}</Value></Eq></And><IsNotNull><FieldRef Name='WorkflowListId' /></IsNotNull></And><IsNotNull><FieldRef Name='WorkflowItemId' /></IsNotNull></And></Where>";
   SPQuery query = new SPQuery();
   query.Query = string.Format(caml, properties.InstanceId);
   query.RowLimit = 1;
   SPList list = web.Lists["Tasks"];
   SPListItemCollection items = list.GetItems(query);
   if (items.Count > 0)
   {
       item = items[0];
   }
   return item;
}
于 2011-05-04T19:25:39.073 に答える
1

この投稿に示されているように、InstanceId プロパティを使用して、ワークフロー タスク リストから SPListItem を取得できます。

http://blog.symprogress.com/2011/09/sp-2010-get-workflow-status-workflowcompleted-event/

于 2011-09-17T12:16:09.077 に答える
0

あなたが詳細をもっと寛大にすることができれば、私は答えをより具体的にすることができます.

しかし、これは一般的にあなたがする必要があることです:

  1. コンテキスト固有のプロパティを設定する

    public static DependencyProperty _ ContextProperty = System.Workflow.ComponentModel.DependencyProperty.Register(" _Context", typeof(WorkflowContext), typeof(MyCustomActivity));

[Description("Site Context")] [Category("User")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

public WorkflowContext __Context
{
    get
    {
        return ((WorkflowContext)(base.GetValue(MyCustomActivity.__ContextProperty)));
    }

    set
    {
        base.SetValue(MyCustomActivity.__ContextProperty, value);
    }
}

public static DependencyProperty __ListIdProperty
    = System.Workflow.ComponentModel.DependencyProperty.Register("__ListId",
    typeof(string), typeof(MyCustomActivity));

[検証オプション(検証オプション.必須)]

public string __ListId
{
    get
    {
        return ((string)(base.GetValue(MyCustomActivity.__ListIdProperty)));
    }

    set
    {
        base.SetValue(MyCustomActivity.__ListIdProperty, value);
    }
}

public static DependencyProperty __ListItemProperty
    = System.Workflow.ComponentModel.DependencyProperty.Register("__ListItem",
    typeof(int), typeof(MyCustomActivity));

[検証オプション(検証オプション.必須)]

public int __ListItem
{
    get
    {
        return ((int)(base.GetValue(MyCustomActivity.__ListItemProperty)));
    }

    set
    {
        base.SetValue(MyCustomActivity.__ListItemProperty, value);
    }
}

public static DependencyProperty __ActivationPropertiesProperty
    = DependencyProperty.Register("__ActivationProperties",
    typeof(Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties), typeof(MyCustomActivity));

[検証オプション(検証オプション.必須)]

public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties __ActivationProperties
{
    get
    {
        return (Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties)base.GetValue(MyCustomActivity.__ActivationPropertiesProperty);
    }

    set
    {
        base.SetValue(MyCustomActivity.__ActivationPropertiesProperty, value);
    }
}
  1. 次のように、コンテキスト__Context とその他すべてを取得します__Context

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { // Invoke イベントを発生させて、ワークフローでカスタム コードを実行します。this.RaiseEvent(MyCustomActivity.InvokeEvent, this, EventArgs.Empty);

    SPWeb _cxtWeb = null;
    String _strLinfo = "Dll;";
    String _strTo = String.Empty;
    
    // Set Context
    try
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (_cxtWeb = __Context.Web)
            {
                //_cxtWeb = __Context.Web;
                Guid _cListId = new Guid(__ListId);
                SPList _cSPList = _cxtWeb.Lists[_cListId]; // TimeLog
                SPListItem _cListItem = _cSPList.GetItemById(__ListItem);
                SMTPSERVER = _cxtWeb.Site.WebApplication
                                            .OutboundMailServiceInstance.Server.Address;
            }
        });
    }
    catch { /**/ }
    

    }

于 2011-05-03T23:12:46.590 に答える