-5

How do i get all items from list? Here is my code,

function checkFreebookingdateTime() {

getListCalender = document.getElementById('CalenderListDrop').value;
spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
context = new SP.ClientContext.get_current();
parentContext = new SP.AppContextSite(context, spHostUrl);
web = parentContext.get_web();
list = web.get_lists().getByTitle(getListCalender);
context.load(list);

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>1000</RowLimit></View>');
collListItem = list.getItems(camlQuery);

context.load(collListItem);

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

}

function onQuerySucceeded() {

var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    var listDetails = oListItem.get_item('EventDate') + "  " + oListItem.get_item('EndDate');

    alert(listDetails.toString());

 }
}

function onQueryFailed(sender, args) {
 alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

I get this error,

TypeError, Unable to set property collListItem or undefined or null reference

0

Instead of

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

try to use simply

context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
0

Declare var collListItem; on top of the function

Remove this prefix's inside the function.

You final code will be

var collListItem;
function checkFreebookingdateTime() {
    getListCalender = document.getElementById('CalenderListDrop').value;
    spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    context = new SP.ClientContext.get_current();
    parentContext = new SP.AppContextSite(context, spHostUrl);
    web = parentContext.get_web();
    list = web.get_lists().getByTitle(getListCalender);
    context.load(list);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><RowLimit>1000</RowLimit></View>');
    collListItem = list.getItems(camlQuery);
    context.load(collListItem);
    context.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
}

function onQuerySucceeded() {
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var listDetails = oListItem.get_item('EventDate') + "  " + oListItem.get_item('EndDate');
        alert(listDetails.toString());
    }
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • Then i get Unable to get property 'onQuerySucceeded' of undefined or null reference – Batistuta Dec 3 '14 at 11:48
  • Remove prefix this before onQuerySuceeded – Amal Hashim Dec 3 '14 at 12:04
0
<script type="text/javascript" src="filelink/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="filelink/jquery.SPServices-0.6.2.min.js"></script>
<script language="javascript" type="text/javascript">
var getListCalender = document.getElementById('CalenderListDrop').value;
var spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
var context = new SP.ClientContext.get_current();
var parentContext = new SP.AppContextSite(context, spHostUrl);
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
webURL: parentContext_webAbsoluteUrl,
listName: getListCalender,
CAMLViewFields: "<View><RowLimit>1000</RowLimit></View>",
completefunc: function (xData, Status) {
  $(xData.responseXML).SPFilterNode("z:row").each(function() {
    alert($(this).attr("ows_EventDate"));
  });
}
});
});
</script>

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.