0

I had a requirement ,Need to get all the items of "Customers" List using JSOM and show in

tag.I had written my code ,But found no luck can any one help me how the issue in below code.

    <script>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);
function retrieveListItems()
{
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('CalerndarExecution');

var camlQuery = new SP.CamlQuery();
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='Function' Ascending='TRUE' /></OrderBy></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();
                listItemInfo +=' <strong>Title:</strong> ' + oListItem.get_item('Function') +'<br />';
                }  $("#p").val(listItemInfo);
}


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

<p></p>
0

Are you getting any error message?

If not try to set the id as p to the paragraph element, like below.

<p id="p"></p>

Because $("#p") is the jQuery selector for id.

Ensure "Function" is a column's internal name use the below code, otherwise replace "Function" with the internalname of the column.

Call the retrieveListItems method by end of the code.

Below is the formatted and working code.

function retrieveListItems() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('CalendarExecution');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='Function' Ascending='TRUE' /></OrderBy></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();
    listItemInfo += ' <strong>Title:</strong> ' + oListItem.get_item('Function') + '<br />';
}
$('#p').html(listItemInfo);
}

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

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);

</script>

<p id='p'></p>

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.