1

i want to query to list items by filtering attachments name with default WCF query. But i get an error. My query is below. Is that possible?

/_vti_bin/ListData.svc/<MyListTitle>?$expand=Attachments&$filter=substringof('foo',Attachments/Name)

Error says

No property 'Name' exists in type 'System.Collections.Generic.IEnumerable`1[[Microsoft.SharePoint.Linq.DataServiceEntity, Microsoft.SharePoint.Linq, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]'

1

It is not supported to apply $filter query option to Attachments field type, it is a similar restriction as for multi-value lookup fields and users.

According to Use OData query operations in SharePoint REST requests:

Queries for multi-value lookup fields and users Because multi-value lookup fields are returned as a string of multiple values, there is no way to query for them (for example, the equivalent of an Includes element or NotIncludes element is not supported).

As a workaround, you could consider to apply filtering to the returned results:

var endpointUrl = 'https://contoso.sharepoint.com/_vti_bin/ListData.svc/Tasks?$expand=Attachments';
var findText = 'Office 365';

$.getJSON(endpointUrl, function(data) {
   var items  = data.d.results;
   var filteredItems = items.filter(function(item){
       var foundAttachments = item.Attachments.results.filter(function(attachment){
           if(attachment.Name.indexOf(findText) > -1)
               return attachment;
       });
       if(foundAttachments.length > 0)
           return item;
   });

   //print filtered results 
   filteredItems.forEach(function(item){
       console.log(item.TaskName); 
   });


});
3
  • Thanks but i am working on something like search on a list and i am looking for specific text for specific column for example Content column also i want to search for attachment name. Is there best practice for this? Maybe i can do store attachments names in another column and search for new column example AttachmentsNames? – Yavuz May 26 '15 at 6:25
  • Creating a separate text column for storing attachment names sounds good. But remember you need to keep it sync with Attachments field – Vadim Gremyachev May 26 '15 at 6:31
  • 1
    Users adding new item in custom webpart programmatically so i can manage sync issue i think. Thanks for your care. – Yavuz May 26 '15 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.