查找从单独列表中筛选的值 [英] Lookup filtered value from separate list

查看:39
本文介绍了查找从单独列表中筛选的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表,其中包含以下列:

I have two lists, with the following columns:

列表A:


  • 名称
  • 项目
  • 从事? (是/否)
  • 开始日期
  • 结束日期

列表B:


  • 项目
  • 资源(从列表A下拉"名称")
  • 开始日期
  • 结束日期

如果任何给定条目中的"名称"列与列表B匹配中的"资源"列匹配,我希望列表A中的"参与"列显示"Y"它,如果列表B中的'结束日期'是在今天的日期之后。

I would like the 'Engaged' column from List A to show a 'Y' if the 'Name' column in any given entry matches the 'Resource' column in List B matches it, AND if the 'End Date' in List B is after today's date.

有没有办法做到这一点?

Is there any way to do this?

提前感谢

推荐答案

创建SharePoint场解决方案并将事件接收器添加到列表B,当项目被添加/更新时,触发事件接收器。

https://www.c-sharpcorner.com/article/introduction-of-sharepoint-event-receivers/

根据列表B中的项目,如果'结束日期'在今天的日期之后,请更新列表A中的查找项。

以下是检查列表B中项目值的示例代码供您参考。

SPList lista = web.Lists.TryGetList("ListA");
                //update listb as properties.ListItem.ParentList in event receiver.
                SPList listb = web.Lists.TryGetList("ListB");
                //replace item with properties.ListItem in event receiver.
                //item(1) just for test purpose
                SPListItem item = listb.GetItemById(1);

                SPFieldLookupValue SingleValue = new SPFieldLookupValue(string.Format("{0}",item["Resource"]));
                DateTime endDate=Convert.ToDateTime(item["EndDate"]);  
                if (SingleValue.LookupValue != null&&endDate>DateTime.Today)
                {
                    int parentItemID = SingleValue.LookupId;
                    SPListItem parentListItem = lista.GetItemById(parentItemID);
                    parentListItem["Engaged"] = true;
                    parentListItem.Update();
                }

最好的问候,

Lee


这篇关于查找从单独列表中筛选的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆