4

からIDを取得しようとすると:

string idValue = item[Lookup].ToString();

例によって次の値を取得します。

1;#1

この方法で値が必要です:

1

実際、このコードは要件を処理します。

using (SPSite site = new SPSite(context.CurrentWebUrl))
{
    using (SPWeb web = site.OpenWeb())
    {
        //Context list                 
        SPList list = web.Lists[context.ListId];
        SPList child = web.Lists[List]; 
        SPListItem currentItem = list.GetItemById(context.ItemId);
        string updateItems = "";
        int ID = currentItem.ID;

        foreach (SPListItem item in child.Items)
        {
            string idValue = item[Lookup].ToString();
            int partial = idValue.LastIndexOf(";");
            string idPure = idValue.Substring(0, partial);

            if (idPure == ID.ToString())
            {
                item[Field] = Value;
                item.Update();
                updateItems += item.ID.ToString();
            }
        }              

        //Return Items*/
        results["Items"] = updateItems;
        SPWorkflow.CreateHistoryEvent(web, context.WorkflowInstanceId, 0,
            web.CurrentUser, TimeSpan.Zero, "Information",
            "Event from sandboxed, updates: " + updateItems, string.Empty);
    }
}

ルックアップ フィールドから ID を取得するためのより良い関数またはプロパティを知りたいです。

4

3 に答える 3