javascript - Caml Query not executing the where part - Stack Overflow

admin2025-04-18  0

I am using the below code to query a SharePoint 2010 external list

    var targetList = web.get_lists().getByTitle('Members');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<view><Query><Where><Eq><FieldRef Name=\'MemberID\'/><Value Type=\'Text\'>mg33</Value></Eq></Where>'+
    '</Query>'+
    '<ViewFields>'+
    '<FieldRef Name=\'MemberID\'/>'+
    '<FieldRef Name=\'Name\'/>'+
    '<FieldRef Name=\'Email\'/>'+
    '<FieldRef Name=\'Department\'/>'+
    '<FieldRef Name=\'Title\'/>'+
    '<FieldRef Name=\'Manager\'/>'+
    '</ViewFields></view>');

    this.collListItem = targetList.getItems(camlQuery);         clientContext.load(collListItem,'Include(MemberID,Name,Email,Department,Title,Manager)');

but the query is retrieving all the list instead of a single record which matches the where statement

I am using the below code to query a SharePoint 2010 external list

    var targetList = web.get_lists().getByTitle('Members');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<view><Query><Where><Eq><FieldRef Name=\'MemberID\'/><Value Type=\'Text\'>mg33</Value></Eq></Where>'+
    '</Query>'+
    '<ViewFields>'+
    '<FieldRef Name=\'MemberID\'/>'+
    '<FieldRef Name=\'Name\'/>'+
    '<FieldRef Name=\'Email\'/>'+
    '<FieldRef Name=\'Department\'/>'+
    '<FieldRef Name=\'Title\'/>'+
    '<FieldRef Name=\'Manager\'/>'+
    '</ViewFields></view>');

    this.collListItem = targetList.getItems(camlQuery);         clientContext.load(collListItem,'Include(MemberID,Name,Email,Department,Title,Manager)');

but the query is retrieving all the list instead of a single record which matches the where statement

Share asked Feb 21, 2012 at 11:35 SSheblySShebly 2,0731 gold badge21 silver badges29 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Try to look at this MSDN article for example: http://msdn.microsoft./en-us/library/hh185007.aspx

And try the following code. I changed xml element "view" to "View" and .load() method has only one parameter. There is no need for the second one.

var targetList = web.get_lists().getByTitle('Members');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('
<View>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name=\'MemberID\'/>
                <Value Type=\'Text\'>mg33</Value>
            </Eq>
        </Where>'+
    '</Query>'+
    '<ViewFields>'+
        '<FieldRef Name=\'MemberID\'/>'+
        '<FieldRef Name=\'Name\'/>'+
        '<FieldRef Name=\'Email\'/>'+
        '<FieldRef Name=\'Department\'/>'+
        '<FieldRef Name=\'Title\'/>'+
        '<FieldRef Name=\'Manager\'/>'+
    '</ViewFields>
</View>');
this.collListItem = targetList.getItems(camlQuery);
clientContext.load(collListItem);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744931561a275186.html

最新回复(0)