0

I am using the following code, but all it is returning is "object object" when I need to return whats actually in the value of the column of the list for each list item. Any suggestions?

The list item I am trying to get is a lookup/dropdown value for the item in the list. I can get any other column data except this one.

            //start of jQuery document ready section
                jQuery(document).ready(function() {

                var basePath = "https://sp.test.com/ts/"; //This is your base site url with "/_api/" appended to the end
                var listName = "TestList"; //This is where you put the name of your picture library


                //start of Ajax query
                jQuery.ajax({
                //
                //This is where you add the fields you would like to return after the "select=". Separate fields by a ","
                url: basePath + "_vti_bin/listdata.svc/"+listName+"?$select=Region1", 
                //
                type: "GET", //This is set to GET so it can pull the data properly
                headers: { "Accept": "application/json;odata=verbose" }, //This just sets the data to be returned as json data
                success: function (data) //data is a system variable which contains the data returned from the server
                {
                jQuery.each(data.d.results, function (index, value) 
                //index is the index of items
                //value is the item being receieved
                //data.d is the serialized data value from the query, and adding .results to the end gets the results of the serialized data
                {
                alert(value.Region1);
            alert(data.d.results);
                });
                },
                error: function (data) 
                {
                //Error gets output here
                alert(data.statusText); //data.statusText displays the status of the call
                },
                //
                complete: function()
                {
                //alert("ah!");
                //Insert any code here that you want to run when the ajax call has completed
                }
                });
                //End of Ajax query
                });
                //End of jQuery document ready section</script>
1
  • I needed to change the basePath portion that read "Region1" to "Region1&$expand=Region1" and then change the alert to read "value.Region1.Id". Aug 31, 2017 at 13:52

1 Answer 1

0

I needed to change the basePath portion that read "Region1" to "Region1&$expand=Region1" and then change the alert to read "value.Region1.Id"

Correct Code:

            //start of jQuery document ready section
                jQuery(document).ready(function() {

                var basePath = "https://sp.test.com/ts/"; //This is your base site url with "/_api/" appended to the end
                var listName = "TestList"; //This is where you put the name of your picture library


                //start of Ajax query
                jQuery.ajax({
                //
                //This is where you add the fields you would like to return after the "select=". Separate fields by a ","
                url: basePath + "_vti_bin/listdata.svc/"+listName+"?$select=Name,Time1,Region1&$expand=Region1", 
                //
                type: "GET", //This is set to GET so it can pull the data properly
                headers: { "Accept": "application/json;odata=verbose" }, //This just sets the data to be returned as json data
                success: function (data) //data is a system variable which contains the data returned from the server
                {
                jQuery.each(data.d.results, function (index, value) 
                //index is the index of items
                //value is the item being receieved
                //data.d is the serialized data value from the query, and adding .results to the end gets the results of the serialized data
                {
                alert(value.Name.toString());
            alert(value.Region1.Id);    
            });
                },
                error: function (data) 
                {
                //Error gets output here
                alert(data.statusText); //data.statusText displays the status of the call
                },
                //
                complete: function()
                {
                //alert("ah!");
                //Insert any code here that you want to run when the ajax call has completed
                }
                });
                //End of Ajax query
                });
                //End of jQuery document ready section</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.