0

I have a javascript and i can't get the CAML or listitems.

//http://vadimtabakman.com/nintex-forms-multilingual-form.aspx

NWF$(document).ready(function () {
    var language = NWF$('#' + varLanguage);

    language.change(function() {
    //alert(language).val(); // else alert error message

    var languageValue = this.value.split(";#")[1];
    alert(languageValue);

    var clientContext = SP.ClientContext.get_current();    
    var oList = clientContext.get_web().get_lists().getByTitle('Survey Label Translation');

    var camlQuery = new SP.CamlQuery();
    alert('line 15');
    camlQuery.set_viewXml(
        '<View>' +
            '<Query>' +
                '<Where>' + 
                    '<Eq>' +
                        '<FieldRef Name=\'Language\'/><Value Type=\'Choice\'>' + Spanish + '</Value>' +
                    '</Eq>' +
                '</Where>' +
            '</Query>' +
        '</View>'
        );  
    alert('line 26');
    this.collListItems = oList.getItems(camlQuery);
    clientContext.load(collListItems);  
    alert('line 30');
    alert(collListItems.status);
    if (collListItems.status == 200)
     {
       var rows = collListItems.responseXML.getElementsByTagName('z:row');

       for(x=0; x < rows.length; x++)
       {
         var listLabelID = rows[x].getAttribute('ows_Title'); // query field + ows prefix
         var listTranslation = rows[x].getAttribute('ows_Translation'); // query field + ows prefix
         translations[listLabelID] = listTranslation;
         var node = NWF$('.' + listLabelID).find('.nf-label-control');
         node.text(listTranslation);
       }
     }
     else
     {
       alert('There was an error: ' + collListItems.statusText); // else alert error message
     }


    });
});

2 Answers 2

0

the filter is confusing. although the field type is choice you have change it to Text like below and wala

 '<FieldRef Name=\'Language\'/><Value Type=\'Text\'>' + languageValue + '</Value>' +
0

I see a couple things in there...

First of all, I'm surprised you're not getting an error message Spanish is not defined.

In your CAML code, you have the word "Spanish", outside of quotes, so it's not being treated as a string, it would be treated as a variable name.

I think maybe what you want in there is:

'<FieldRef Name=\'Language\'/><Value Type=\'Choice\'>' + languageValue + '</Value>' +

Secondly, although you build up your query and request for stuff from SharePoint, you never actually send off the query to the server to get processed. After you do context.load(stuffYouWant) you still have to context.executeQueryAsync() to send the request to the server.

Keep in mind executeQueryAsync takes two arguments - the success callback and the failure callback.

Check out this documentation on executeQueryAsync and this other example of how to retrieve list items.

2
  • I can't get the following to work var rows = collListItems.responseXML.getElementsByTagName('z:row'); for(x=0; x < rows.length; x++) Oct 18, 2019 at 20:30
  • The z:row thing comes into play when you are using the old 2010 ListData.svc endpoint, which is used by the popular SPServices library. However, you do not seem to be using SPServices, you are using the regular SP2013 CSOM library. Again, I would suggest you look at the example I linked to in my answer, it shows how to call executeQueryAsync with the callback functions, and in the success callback, use getEnumerator() and moveNext() to loop through the items. What happens if you console.log(collListItems) just before you try to get the rows out of it? What do you see? Oct 18, 2019 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.