none
Filter results for items that contain a single value on Multi-Value column RRS feed

  • Question

  • Consider the following:

    Sharepoint List called Projects with two columns.  Title and EntityId (unrelated to SP id)

    Sharepoint List called Rules with three columns: Title, Action, Project (allows multiple values)

    I would like to create a query that will return all of the rules that have a specific project in the list.

    To add the item I've used the spContext.AddLink(ruleEntity, "Project", projectEntity) and that works correctly.

    However, I'm struggling with retrieving all the results that contains the specific project that I'm looking for.  I've been able to retrieve all results and expand the values of Project, then filter the list locally using Linq Contains function.  But when I tried to add the contains predicate to the DataServiceQuery I receive a not supported exception, and I'd like to avoid retrieving all values.   Is there a way to do this with DataServiceClient?

    Thursday, January 19, 2017 1:45 PM

Answers

  • Hi Greg,

    Then we can use CAML Query to filter the specific value within a multiple lookup value field like below using SharePoint Client Object Model:

    ClientContext clientContext = new ClientContext("your site"); 
    Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("List10"); 
    clientContext.Load(spList); 
    clientContext.ExecuteQuery(); 
    
    if (spList != null && spList.ItemCount > 0) 
    {
       Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery(); 
       camlQuery.ViewXml = 
          @"<View>  
                <Query> 
                   <Where><Eq><FieldRef Name='multiplelv' /><Value Type='LookupMulti'>Emp2</Value></Eq></Where> 
                </Query> 
          </View>";  
    
       ListItemCollection listItems = spList.GetItems(camlQuery); 
       clientContext.Load(listItems); 
       clientContext.ExecuteQuery(); 
    }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 26, 2017 7:58 AM

All replies

  • Hi Greg,

    If the Project field is a multiple value lookup field, then we can use linq to fiter the field like the code demo below:

    SPMetal SharePoint LINQ Filter on Multi-Value Lookup Field

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, January 25, 2017 10:45 AM
  • Thank you Jerry.  That is what I ended up doing.  However, the .ToList() is returning the full results of the SharePoint List to the client before being filtered locally.  This works, but I would prefer to only retreive the results that have the specific project I'm looking for with the query.
    Wednesday, January 25, 2017 11:27 AM
  • Hi Greg,

    Then we can use CAML Query to filter the specific value within a multiple lookup value field like below using SharePoint Client Object Model:

    ClientContext clientContext = new ClientContext("your site"); 
    Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("List10"); 
    clientContext.Load(spList); 
    clientContext.ExecuteQuery(); 
    
    if (spList != null && spList.ItemCount > 0) 
    {
       Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery(); 
       camlQuery.ViewXml = 
          @"<View>  
                <Query> 
                   <Where><Eq><FieldRef Name='multiplelv' /><Value Type='LookupMulti'>Emp2</Value></Eq></Where> 
                </Query> 
          </View>";  
    
       ListItemCollection listItems = spList.GetItems(camlQuery); 
       clientContext.Load(listItems); 
       clientContext.ExecuteQuery(); 
    }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 26, 2017 7:58 AM