Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Getting a single item not a full list with Java Script?

$
0
0

Hey all

Using the below link as refrence I have made Java Script in a display form of a list item, i am trying to get the information of just the display forum but right now i am getting everything in the list (5 items currently). how would i get one item rather then a full list. this is also in SharePoint online where as the article i used is 2010 so there may be a difference there.

https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/hh185007(v=office.14)

<script src="/SiteAssets/JQuery/jquery-dateFormat.min.js" type="text/javascript"></script><script>

ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");

var siteUrl = 'https://SiteName.sharepoint.com/';

function retrieveListItems() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Test HC 1');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
        '<Value Type=\'Number\'>1</Value></Geq></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 += '\nTitle: ' + oListItem.get_item('Title') + 
            '\nHits: ' + oListItem.get_item('Hits');    
    }
    alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>