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

JavaScript and getItemById!

$
0
0
hi all,

I have this issue: I want access the item by ID but I get error and I give the right ID here but still dont work
                  and I get: TypeError: targetList.GetItemById is undefined
its in the onQuerySecceeded-function.
   alert(_spPageContextInfo.pageListId);
        var currCtx = new SP.ClientContext();
        var targetList = currCtx.get_web().get_lists().getByTitle('DemoList');
        var query = new SP.CamlQuery();
        query.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Title' /> <Value Type='Text'>" + "FName, LName" + "</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query></View>");
        listItems = targetList.getItems(query);
        currCtx.load(listItems);
        currCtx.executeQueryAsync(onQuerySucceeded, onQueryFailed);

        function onQuerySucceeded() {

            var listItemInfo = '';

            var count = listItems.get_count();

            if (count >= 0) {
                alert('No of rows: ' + count);
                var listItemEnumerator = listItems.getEnumerator();
                var x = new Array();
                var i = 0;
                while (listItemEnumerator.moveNext()) {
                    var oListItem = listItemEnumerator.get_current();
                    x[i] = oListItem.get_id();
                    i++;
                }
               /* The code work fine until here! Here I want use getItemById and I cant!*/var oItem;
                var listItemEnumerator1 = listItems.getEnumerator();
                while (listItemEnumerator1.moveNext()) {
                    var oListIte1m = listItemEnumerator1.get_current();
                    oItem = targetList.getItemById(oListItem.get_id());alert("ID: " + oItem.get_id());
                }
            }




        }

        function onQueryFailed() { alert("Error - Failed"); }

thanks in advance
Ahmad


SP 2013 & SPD 2013 & VS 2013 & MSSQL 2012






Viewing all articles
Browse latest Browse all 7589

Trending Articles