Unable to get List Items with CAML Query

hello Support Team,
I’d need help on how to configure code to retrieve data with Caml Query please.
I have a list (PurchaseOrder) with Forms. When I choose a Client, in that form, I would need to get all items in a second list (ClientsAndProviders) with a CAML Query, filtering by two different fields.
Unfortunately I’m not getting any results.
I’m working on Sharepoint 365 and Plumsail Forms 1.4.4.
This is the code I’m using:

retrieveListItems();

function retrieveListItems() {
	var SiteUrl = 'https://development01.sharepoint.com/';
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('ClientsAndProviders');
        
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name='DittaTxt' /><Value Type='Text'>Top Single Service srl</Value></Eq><Eq><FieldRef Name='ClienteTxt' /><Value Type='Text'>2T srl</Value></Eq></And></Where></Query><RowLimit>10</RowLimit></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();
        listItemInfo += '\nID: ' + oListItem.get_id() + 
        '\nClienteTxt: ' + oListItem.get_item('ClienteTxt');
    }

    alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

At the end, I would need an example on how to get Items from a list via Caml Query. Thanks

Hello @AleStendardo!

You can get items with pnpjs. Please see the example with filtering below and also have a look at this article

pnp.sp.web.lists.getByTitle("Test").items.select("Title,ID").filter("Title eq 'Test' and ID eq '10'").getAll().then(function(allItems){
console.log(allItems);
});.

hello @mnikitina, thank you for your support. I tried it and it works fine.

Cheers

1 Like