0
votes

I have created a caml query for fetching data in sharepoint application.I have used contains in where clause.I am not getting the data at the time of executing this query because "#" is preset in the starting of input value(#userdetails). How to solve this issue. Please help.

Query:

<Where>
    <Contains>
        <FieldRef Name='FileRef' />
        <Value Type='Text'>#userdetails</Value>
    </Contains>
</Where>
1
Can you please paste de CAML you are using?jpussacq
<Where><Contains><FieldRef Name='FileRef' /><Value Type='Text'>#userdetails</Value> </Contains> </Where>Rojish Varughese
Which sharepoint type column is userdetails?jpussacq

1 Answers

1
votes

I don't know why your code does not work when there is # in your input value in caml query.

But Refer below code that works perfectly for me.

function retrieveListItems() {

    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('TestList');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Contains><FieldRef Name="Title" /><Value Type="Text">#rohit</Value></Contains></Where></Query></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        alert(oListItem.get_item('Title'));
    }

    alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {
    debugger;
}