Filter on audience in caml query

hello ,
I have enabled audience on a SharePoint list and i would like to filter returned items on OOTB audience field in my caml query.
How to achieve my goal ?
Thanks.

CALM
Query to filter the “Target Audiences” field:
<Query><Where><Eq><FieldRef
Name=' Target _x0020_Audiences '/><Value
Type=’TargetTo’>your
GUID</Value></Eq></Where></Query>
Please
note that the value of the Target audiences is displayed as GUID, you can find the GUID :your user profile service application >Manage Audiences>open your Audience>you will find the GUID in the page URL. Or you can open the list AllItem.aspx
page using SharePoint Designer, you will find the GUID .
Links
https://social.technet.microsoft.com/forums/sharepoint/en-US/2f9a13eb-89df-4744-8a01-38a3d9e2ce99/how-to-filters-the-target-audiences-using-the-caml-query
https://jamesheppinstall.wordpress.com/2012/08/06/filtering-a-caml-query-by-target-audience/
Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

Similar Messages

  • Filter SharePoint list items using CAML query as same as Like operator in SQL Server.

    Hi ,
    I have filtered SharePoint list items based on Name using CAML query <Contains> . Now I have a new requirement is to filter list items using Like operator in SQL. But Like operator is not in CAML.
    How do I filter list items using CAML as same as Like operator in SQL.
    Please let me know.
    Thanks in Advance.

    Did you try using <Contains>?
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/15766fd5-50d5-4884-82a1-29a1d5e38610/caml-query-like-operator?forum=sharepointdevelopmentlegacy
    --Cheers

  • CAML Query help using recursiveall and date filter together

    Hello,
    Please let me know what is wrong with the query below,
    <View Scope='RecursiveAll'>
    <Query>
    <Where>
    <Leq>
    <FieldRef Name='Modified'/>
    <Value Type='DateTime' IncludeTimeValue='FALSE'>date value</Value>
    </Leq>
    </Where>
    </Query>
    </View>
    Above query returns zero items, it should return 3 items in my current scenario.
    If I do just the folllowing, three items are returned
    <View Scope='RecursiveAll'>
    <Query>
    </Query>
    </View>
    I need date filter to work with recursiveall . Not sure what is wrong with the query
    Student For Life

    Hi,
    Per my understanding, you might want to use “RecursiveAll” with date filter in your CAML query statement.
    I suggest you take the code demo below which writes in Server Object Model for a try in your environment to see if it can work for you:
    using (SPSite oSiteCollection = new SPSite("http://yoursite"))
    using (SPWeb web = oSiteCollection.RootWeb)
    SPList list = web.Lists["List1"];
    SPQuery qry = new SPQuery();
    qry.Query =
    @" <Where>
    <And>
    <Leq>
    <FieldRef Name='Modified' />
    <Value Type='DateTime'>2015-03-07T12:00:00Z</Value>
    </Leq>
    <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>0</Value>
    </Eq>
    </And>
    </Where>";
    qry.ViewFields = @"<FieldRef Name='Title' />";
    qry.ViewAttributes = "Scope='RecursiveAll'";
    SPListItemCollection items = list.GetItems(qry);
    foreach (SPListItem item in items)
    Console.WriteLine(item["Title"]);
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Retrieve All records and display in Report using CAML query in Report Builder if Parameter value is blank

    Hello Experts,
    i have created a report where i have one parameter field where user will pass parameter(e.g. EmpId). As per parameter record will fetched to report if no parameter is passed then it will display all records. I have done it by taking SqlServer Database as datasource.
    by using Following method
    Now i would like to do it by taking Sharepoint List as Datasource. For that what would be the CAML Query.
    Here is my existing CAML query.
    <RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ListName>Employees</ListName>
      <ViewFields>
        <FieldRef Name="Title" />
        <FieldRef Name="FirstName" />
        <FieldRef Name="LastName" />
        <FieldRef Name="FullName" />
        <FieldRef Name="UserName" />
        <FieldRef Name="Company" />
      </ViewFields>
      <Query>
        <Where>  
    <Eq> 
        <FieldRef Name="Title" />
      <Value Type="Text">    
       <Parameter Name="EmployeeId"/>    
    </Value>
    </Eq>                  
        </Where>
      </Query>
    </RSSharePointList>
    The above code is working if i am passing an employeeId to Parameter. If nothing is passed, it is Not retrieving any record.
    Please suggest
    Thank you
    saroj
    saroj

    Your problem follows the well-established pattern of using an "All" parameter filter in SSRS. There are a few approaches depending on the size of your data. The easiest one is to return all data from CAML and then filter it within SSRS, the following thread
    provides some examples,
    http://stackoverflow.com/questions/18203317/show-all-records-some-records-based-on-parameter-value.
    Other options include passing all of the possible values within the CAML query when "All" is selected, using multiple Report Files to distinguish between both CAML queries, or to use multiple datasets with some logic to show/hide the correct one.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • URL data type in CAML Query with Client side object model

    hi,
    How do I write a CAML query to filter list items based on the URL field using it's Description?
    Same with REST API. How do I construct a REST query so that filter list items based on the URL data type using it's Description.

    Hi Cooltechie,
    Thanks for posting your query, Below are the example that you can use in your CAML query
    <Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">sites/SiteCollection/SubSite/Site Documents/Excel Report.xls</Value></Eq></Where>
    Note: Do not include the server name or beginning /.
    The following examples assuming you have a list or library setup with a URL column named "My Document".
    The link is to a document that is hosted on the sharepoint server (do not need server name):
    <Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">/sites/subsite/Site%20Documents/Excel%20Report.xls</Value></Eq></Where>
    The link is an absolute URL to something not on the server... for example http://www.google.com:
    <Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">http://www.google.com</Value></Eq></Where>
    I hope this is helpful to you, mark it as Helpful.
    If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • CAML query on SharePoint list not working after reaching threshold limit

    I have written CAML query to filter and get list items. It was working fine, but the List items count crossed 5000 and its around 15000 items. In Server Object Model When i execute my query to get list items throws exception as " The
    attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator ".
    My Code:
    SPList list = web.Lists["ComplaintReturnsForm1"];
    string QIRIdNo = fldQIRIdNo.Text;
    SPQuery query = new SPQuery();
    query.Query = "<Where><Eq><FieldRef Name='fldQIRIdNo' /><Value Type='Text'>" + QIRIdNo + "</Value></Eq></Where>";
    SPListItemCollection itemcoll = list.GetItems(query);
    Please help me to fix it. 

    Hi Mario,
    Thanks a lot for your reply.
    query.Query = "<Where><Eq><FieldRef Name='fldQIRIdNo' /><Value Type='Text'>"
    + QIRIdNo + "
    in this CAML query i have indexed my field "fldQIRIdNo". Now i have more then 5000 items in list, and
    iam able to get my list item data without any error.
    Please let me know if my action is wrong.

  • CAML Query to Exclude the file names inside "Archive" folder

    Hi,
    I need to exclude the files which is already in the "Archive" folder in the same document library. Is there any CAML query to filter only the files from the document library(Exclude the "Archive" folder) files.
    Thank you,
    Mylsamy

    Hi,
    Below link might help you 
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/35e799a1-9360-46e5-8719-dd35fdace7ea/filter-document-library-folder-through-caml-query?forum=sharepointdevelopmentlegacy 
    Thanks
    Sivabalan

  • CAML Query against content type

    Hi
    I am trying to query a Document library by content type using CAML:
    SPQuery qry = new SPQuery();
    string query = <Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='Text'>0x0101003de59dc6676b4ab49e4eb231a59ac906</Value></BeginsWith></Where>;
    qry.Query = query;
    SPListItemCollection items = docLib.GetItems(qry);
    int itemCount = items.Count(); //this is 0
    When I run this, no items are returned.  However, when I go into the default view of the document library and filter against the content type, I can see documents are associated to that content type.  Was wondering why I can see the documents
    in the filtered default view, but the CAML query does not return any items. 
    Any advice or direction to some online resource would be greatly appreciated.
    Thank you in advance
    Rachael

    I tested on a document library with document content type, the following two works:
    <Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='Text'>0x0101007764851CB5A6344EB5C9E35447D01F39</Value>
    <Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='Text'>0x0101</Value>
    0x0101007764851CB5A6344EB5C9E35447D01F39 is the content type id of the list content type and 0x0101 is the content type id of the site content type.
    but what follows does not work:
    <Where><BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='Text'>0x01010</Value>
    By the way, i sugguest using the value type ContentTypeId instead of Text as the CAML generated by LINQ described in: 
    http://msdn.microsoft.com/en-us/library/ff798478.aspx

  • CAML query performance for large lists

    I have a list with more than 10000 items. I am retrieving the items and displaying it in a RAD Grid on my page using CAML query. While retrieving the items, around 1000 records are retrieved due to filter. I have enabled paging in my grid and PageSize is
    set to 25. I have noticed that the load time of my page is very slow as it retrieves all the 1000 records at once.
    Is it possible to retrieve just 25 records for the first page on load. On click on the Next button or Page number it should retrieve the next set of 25 records for that particular page.
    I want to know if there is any way to link CAMl query paging with RAD grid paging
    Any code example would be greatly helpful.

    Hi,
    For pagination in SPListItem use the SPQuery.ListItemCollectionPosition property. 
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.listitemcollectionposition(v=office.15).aspx
    check the usefull urls
    http://omourad.blogspot.in/2009/07/paging-with-listitemcollectionposition.html
    http://www.anmolrehan-sharepointconsultant.com/2011/10/client-object-model-access-large-lists.html
    Anil

  • CAML query for more than two items in a list and bind those result to gridview?

    Hi Team,
    I am binding sharepoint 2013 list to gridview programatically.
    Now i need to search the results. If i gave some key word in text box and click on search.
    Then it should display only those values in gridview using caml query.
    Below is my form.

    Hi,
    Here is a blog about the CAML Query with Multiple Conditions for your reference:
    http://aasai-sharepoint.blogspot.com/2013/02/caml-query-with-multiple-conditions.html
    If you want to filter the list item, here is a web part from codeplex with the source code for your reference:
    SharePoint ListView Filter
    https://splistviewfilter.codeplex.com/
    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Dennis Guo
    TechNet Community Support

  • Sharepont Designer saves AND/OR CAML Query groups incorrectly

    My objective is to display active tasks on a certain date: Started on or before and Due on or after; Started on or before and not Completed.  The date is provided via a webpart connection parameter.
    I used CAML Designer 2013 and SP CAML Query 2013 to verify and then modified the Query string for the Tasks WebPart in Sharepoint Designer as follows:
    <Query><Where>
    <Or>
    <And>
    <Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
    <Geq><FieldRef Name="DueDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Geq>
    </And>
    <And>
    <Neq><FieldRef Name="Status"/><Value Type="Text">Completed</Value></Neq>
    <Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
    </And>
    </Or>
    </Where></Query>
    However, when I save the page in SharePoint Designer, and edit the web page from the browser, the Filter criteria are:
    Start date Less than or equal to {ParmMeetingDate}
    AND DueDate Greater than or equal to
    AND Task Status is not equal to Completed
    OR Start Date is less than or equal to {ParmMeetingDate}
    If I correct the settings in the browser and save, the Query String in SPD is changed to:
    <Query><Where>
    <Or><Or>
    <And>
    <Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
    <Geq><FieldRef Name="DueDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Geq>
    </And>
    <Leq><FieldRef Name="StartDate"/><Value Type="DateTime">{ParmMeetingDate}</Value></Leq>
    </Or>
    <Neq><FieldRef Name="Status"/><Value Type="Text">Completed</Value></Neq>
    </Or></Where></Query>
    How can I get SPD/SP to save the CAML query correctly?

    Update:  Another effect of the problem outlined above was that no results were displayed for any parameterised filter values - regardless of the query.
    I came across a reference to the Server Render webpart attribute.  When this attribute is selected on the webpart a number of things happen:
    The Timeline at the top of the Tasks list view webpart is switched off
    The completed icon changes to a Yes/No value
    The filters work!!!
    Saving the filters works!!!
    The List View Tools tab appears in SharePoint Designer!!!
    I have no idea what the Server Render attribute is and/or why it is set off by default.  I don't why it affects the appearance of the List View Tools tab in the ribbon - I can't think of any reason why it should.  And I don't know why it affects
    the filter query or why it should...
    At a high level I presume the Server Render attribute tells sharepoint to process on the server rather than on the client.  It may make sense to pas the processing from the server to the client.  It makes no sense that this would restrict functionality
    (disable List View Tolls in SPD) or produce different results (no results in Filtered webpart).
    Do you know if this issue has been identified as a bug; has it been resolved?

  • Problem with lookup value by CAML query.

    I just cannot figure out what is wrong with my code that the query does not filter any item. It returns all items in the list. The RowLimit does work so I know the query is used. I wish someone can point out what is wrong in the query. Many thanks.
    SPList tList = cWeb.Lists[listName];
    SPQuery LookupQuery =
    new
    SPQuery();
    //LookupQuery.RowLimit = 5;
    LookupQuery.Query =
    "<Query><Where><Eq><FieldRef Name='ItemStatus' /><Value Type='Text'>New</Value></Eq></Where></Query>";
    SPListItemCollection iColl = tList.GetItems(LookupQuery);
    int n = iColl.Count;

    Try removing the starting and ending <Query> tags. Your CAML query assignment should look like below
    LookupQuery.Query = "<Where><Eq><FieldRef Name='ItemStatus' /><Value Type='Text'>New</Value></Eq></Where>";
    Ram Prasad Meenavalli | MCITP | MCTS SharePoint | MCPD SharePoint | http://www.spdeveloper.co.in

  • Sum and group by using CAML query

    Is there any way to get the SUM of values with group by ID using CAML query?
    I have a custom list, in that I have ID and Value columns as below
          ID         Value1      Value2
          1             10             4
          2              5              3
          1             15             2
          3             20             1
    I want to get result:
         ID          Value1        Value2
         1             25                6
         2             5                  3
         3             20                1
    I used CAML query:
    <View>
    <Query>
    <Where>
    <IsNotNull>
    <FieldRef Name="ID" />
    </IsNotNull>
    </Where>
    <GroupBy Collapse="FALSE">
    <FieldRef Name="ID" />
    </GroupBy>
    </Query>
    <ViewFields>
    </ViewFields>
    <Aggregations Value="On">
    <FieldRef Name="Value1" Type="SUM" />
    <FieldRef Name="Value2" Type="SUM" />
    </Aggregations>
    </View>
    But
    this query returns all the records
    that satisfy the condition <Where>.
    I
    do not correctly?

    You need to work with current view based aggregation. Please check below threads for your reference.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/dda5735a-fecf-403f-9495-1b63617d2fbf/question-on-a-caml-query?forum=sharepointdevelopmentlegacy
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/24e88d6a-ee15-4d81-a5fe-504c7bd14e46/how-to-sum-a-column-value-using-caml-query?forum=sharepointdevelopment
    Hope this helps.
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful
    I've seen these
    issues and articles and do them, but
    does not work. I use object mozhel
    Sharepoint (javascript).

  • Value does not fall within the expected range while passing a spfieldlookupvalue in a caml QUERY

    i have to pass a column from master list -single line of text - and this will be the lookup of another column in another list
    splist1---> column1 [ free text]
    splist2--> column2  [ lookup column of the above list -splist1]
    now am writing a  caml query :
       objDisciNodeQuery.Query =
                                          string.Format(
                                       "<OrderBy>" +
                                         "<FieldRef Name='ID' />"
    +
                                      "</OrderBy>" +
                                       "<Where>" +
                                        "<And>" +
                                          "<Eq>" +
                                             "<FieldRef
    Name='somecolumn' />" +
                                             "<Value
    Type='Text'>{0}</Value>" +
                                          "</Eq>" +
                                          "<Eq>" +
                                             "<FieldRef
    Name='column2' LookupId='TRUE' />" +
                                             "<Value
    Type='Lookup'>{1}</Value>" +
                                          "</Eq>" +
                                         "</And>" +
                                       "</Where>", valueofsomecolumn, lookupidvalueofcolumn2);
                                        SPListItemCollection splistItemAssocCollec
    = null;
                                        splistItemAssocCollec = splist2.GetItems(objDisciNodeQuery);
    here it throws Value does not fall within the expected range
    Anyone has idea why i am getting this error, .
    any ideas  are appreciated.

    We can use lookup column in caml query link this
    <Where>
    <Eq>
    <FieldRef Name=’Departments’ LookupId=’TRUE’ />
    <Value Type=’Lookup’>10</Value>
    </Eq>
    </Where>
    Multi lookup column reference 
    http://naimmurati.wordpress.com/2013/12/03/multi-lookup-fields-in-caml-queries-eq-vs-contains/

  • Join two list with condition using caml query in SharePoint 2013 with client object model

    Hi,
    Want to join two list to get all fields from both list.
    Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
    with joins.  I did lot of surfing..but not..
    Below is my code..
    ListName1 : "AssignedTasks"
    ListName2 : "Tasks"
     var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
                    + "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
                    + "<ProjectedFields>"
                    + "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
                    + "</ProjectedFields>"
                    + "</View>";
                   var web = context.get_web();
                    var list = web.get_lists().getByTitle("AssingedTasks");
                    var myQuery = new SP.CamlQuery();
                    myQuery.set_viewXml(assignedQueryTest);
                    var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
                    context.load(myItems);
                    context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
    }, errorCallback);
    Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values. 
    Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
    If anybody have good sample, please provide.
    Thanks,
    Pariventhan
    Pariventhan.S

    Hi Pariventhan,
    I don't know about join but I have a workaround of this problem.
    Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
    In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
    If this is not clear to you then please let me know. If possible then I can provide code sample.
    Thanks,
    Aniruddha

Maybe you are looking for