0

This query return duplicate record. I want to get only unique record. I want to fetch like my list contains User1, User2, User1 I want get record User1 and User2.

    var context = new SP.ClientContext();  
         var list = context.get_web().get_lists().getByTitle('Users');  
         var caml = new SP.CamlQuery();  
         caml.set_viewXml("<View><Query><Where><BeginsWith><FieldRef Name='Customer' /><Value Type='Text'>"+name+"</Value></BeginsWith></Where></Query></View>");  
         returnedItems = list.getItems(caml);  
         context.load(returnedItems);  
         //Run the query asynchronously, passing the functions to call when a response arrives  
         context.executeQueryAsync(onSucceededCallback, onFailedCallback);


  function onSucceededCallback(sender, args) { 
         //Get an enumerator for the items in the list  
         var enumerator = returnedItems.getEnumerator();
}
  • Is "Users" list custom list ? Does your list have "allow unique values" for name column ? – Monica Jagani Nov 4 '16 at 6:41
  • List contains duplicate name i want to fetch only unique name record. – Admin Nov 4 '16 at 6:44
  • As you are using <BeginsWith> so duplicate is expected. Change it so <Eq> if you can. – Atish Dipongkor - MVP Nov 4 '16 at 6:44
  • Thanks for reply Atish but i check Customer name in this customer name has multiple user with same name user i want to get unique record.Same issue for <Eq> i try it. – Admin Nov 4 '16 at 6:47
  • 1
    unique records based on what? you list has duplicate customer names so CAML will give you duplicates. So now you have to find them using different column. Another thing you can do is: remove duplicates from your list – Atish Dipongkor - MVP Nov 4 '16 at 6:55
0

Try

<RowLimit>1</RowLimit>

to get first record from the result set.

  • No this is not work for me i want to fetch like my list contains User1,User2,User1 I want get record User1 and User2. – Admin Nov 4 '16 at 7:09

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.