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

Unable to retrieve data value in form list Fields using Javascript

$
0
0

I am having difficulty figuring out hold to get data form a list in SharePoint. I have try numerous methods that I have from other peoples code examples. I get the following error "the property or field has not been initialized. it has not been requested or the request has not been executed. it may need to be explicitly requested.".

I have copied and pasted others exactly but no good so I am hoping that someone point me in the right direction. I am new to developing apps in sharepoint so I am sure that's part of it. I am using VS 2015 I have an online developers account where I am using sharepoint online. I will give you copy of the code.

I have a very simple list named "PilotNames" with 3 columns: LastName, FirstName, Initials.

I would like to access the data values in all fields, but right now I am only trying to get the LastName column

The code works to up getting the value for the LastName.

Any suggestions or help would be greatly appreciate, I never thought trying to access data fields would be so difficult. I have had numerous of experience with VS VB.NET, C, and SQL. Yikes HELP, I have spent way to much time on this simple problem.

Thanks for the help.

function getList2() {
        var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
        var currentcontext = new SP.ClientContext.get_current();
        var hostcontext = new SP.AppContextSite(currentcontext, hostUrl);
        var web = hostcontext.get_web(); // hostcontext instead of currentcontext
        var lists = web.get_lists();
        var list = lists.getByTitle('PilotNames');
        var camlQuery = new SP.CamlQuery();        
        camlQuery.set_viewXml('<View></View>');        
        listItemCollection = list.getItems(camlQuery);        
        context.load(listItemCollection);
        context.executeQueryAsync(oGetList2QuerySucceeded, onGetList2QueryFailed);
    }
    function oGetList2QuerySucceeded() {
        var listItemInfo = '';
        var listEnumerator = listItemCollection.getEnumerator();
        while (listEnumerator.moveNext()) {
            var oListItem = listEnumerator.get_current();
            listItemInfo += '\nID: ' + oListItem.get_id();
            listItemInfo += ' LastName: ' + oListItem.get_item('LastName');           
        }
        alert(listItemInfo);
    }
    function onGetList2QueryFailed(sender, args) {
        document.getElementById("TestPanel").innerText =
                "Requested failed AGAIN!!!: " + args.get_message();       
    }


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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