1

リスト (Products) があり、別のリスト (Sales) のルックアップ列として使用されます。

製品リストのアイテムが編集された場合、製品リストを参照している販売リストのすべてのアイテムで実行されるワークフローを開始することは何とか可能ですか?

4

1 に答える 1

0

どのツールを使用しますか? SharePoint Designer の場合、SharePoint Designer は、指定されたリスト (あなたの場合は Sales) 内の複数のアイテムのクエリに関しては弱いため、それを行うことはできません。

それにもかかわらず、コードで手を汚すつもりなら、それは間違いなくイエスです。販売リストのワークフローを既に設計していると思います。「アイテム更新」イベントの「商品」リストにイベントハンドラを登録します。Karine は、イベント ハンドラーの登録に関する素敵な投稿をここに投稿しています。

イベント レシーバーには、次のコードのようなものを配置する必要があります。

//Opening a connection to the site
using (SPWeb web=properties.OpenWeb())
{
    //Getting Sales List
    SPList SalesList=web.Lists["Sales"];

    //Building and executing a CAML query to be executed on the sales list to retrieve sales that are related to the product item currently being updated. Note that you need to replace 'RelatedProduct' with the name of the lookup field in sales list that looks up on items in products list.
    SPQuery qRelatedSales=new SPQuery();
    qRelatedSales.Query=string.Format("<Where><Eq><FieldRef Name='RelatedProduct' LookupId='TRUE' /><Value Type='Lookup'>{0}</Value></Eq></Where>",properties.ItemId);
    SPListItemCollection relatedSales=SalesList.GetItems(qRelatedSales);

    //starting workflow on each related sales item. Note that you have to replace "Your Workflow Name" with the title of your workflow on sales list.
    SPWorkflowAssociation assoc = SalesList.WorkflowAssociations.GetAssociationByName("Your Workflow Name", CultureInfo.CurrentUICulture);
    foreach(SPListItem relatedSale in relatedSales)
    {
        web.Site.WorkflowManager.StartWorkflow(relatedSale, assoc, string.Empty, SPWorkflowRunOptions.Synchronous);
    }
}

この後、製品項目が更新されるたびにプロジェクトとテストを展開し、イベント レシーバーを実行し、最終的に製品に関連するすべての販売項目でワークフローを実行する必要があります。

于 2013-08-09T17:43:17.217 に答える