Sharepoint - Results from REST API Query returning an undefined field

Utilizing REST/JS calls to populate specific fields from a particular list item has presented some challenges for me. The issue arises when attempting to retrieve certain fields, as they are showing up as undefined in the displayed results. Upon examination, it seems that the problematic fields fall under types such as Lookup, Person or Group, and Choice. Conversely, fields of type Single line of text, Date and Time, and Number are displaying correctly. Despite extensive research through various articles, I have yet to find a solution. Below is an excerpt of the code snippet in question:

$(function() {

    $.ajax({
            url: "__URL__/_api/lists/getbytitle('Master%20Project%20List')/items?&$filter=Number eq '" + projectId + "'",
            headers: {"Accept": "application/json;odata=verbose"}, 
            type: "GET", 
            cache: false,
            async: false,      

    }).success(function (data) {
        $.each(data.d.results, function(key, value) {

            //Project Title
            console.log("TEST TITLE - " + value.Title);
            Title = "*" + value.Title; 

            //Project Divison
            console.log("TEST DIVISION - " + value.Div);
            division = "*" + value.Div;

        }); 
    });
}); 

For further insights on a similar issue, refer to this post:

Answer №1

To retrieve specific field values, you may need to explicitly use the $select and $expand options.

The $expand option determines which projected fields from a joined list are included in the response.

In their article "SharePoint 2013 - Understanding the SharePoint 2013 REST Interface," Jim Crowley and Ricky Kirkham explain how lookup fields work in SharePoint lists:

If a SharePoint list includes a lookup field to another list, it essentially creates a join between the two lists. By using the $expand option, you can fetch projected fields from the joined list. For instance, if the Books list has a PublishedBy field that references the Name field in a Publisher list, you can retrieve those names using this URL:

_api/web/lists/getByTitle(
  'Books')/items?$select=Title,PublishedBy/Name&$expand=PublishedBy

It's worth noting that you indicate the column in the foreign list by following the syntax

lookup_column_display_name/foreign_column_name
, rather than
foreign_list_name/foreign_column_name
. Also, selecting a lookup field name requires expanding it as well.

For additional instances, check out the responses provided in this query on the SharePoint Stack Exchange platform.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Organizing entries based on the quantity of attached documents

I am currently working with mongodb and mongoose. I have a situation where users can create ratings and reviews for products. I want to retrieve the review of the product that has received the highest number of votes. Is this achievable in mongo? The data ...

Creating a scheduled redirect button using JavaScript and another button to cancel it

I'm facing an issue with my code. When the first button is clicked, it redirects the user to a different URL after 10 seconds. However, I'm struggling to make the second button cancel the redirect if pressed before the 10 seconds are up. Despite ...

Exploring the world of jQuery AJAX requests by sending POST data to a PHP

I am currently in the process of building a cross-platform application utilizing HTML, CSS, and jQuery/JavaScript. My approach involves using AJAX requests to retrieve data from a database and send data to it as well. I have successfully implemented the &a ...

"Feeling puzzled by the intricacies of the Jquery Timer

I am currently using the jQuery Timer plugin from to dynamically generate documents every 5 seconds with pause and resume functionality. Below is my script: $(function() { $('.handler').load("../Pages/csFetchCustomer.ashx?"); ...

It seems that although both axios.put methods are identical, only one is functioning properly

Could someone clarify the distinction between these two syntaxes and why the first one is not functioning correctly? Attempting to use the first code block results in a 401 error: const handleSubmit = () => { axios.put(`url`, { headers: { Aut ...

Progress bar displaying during Ajax request

I'm currently working on an Ajax request that uploads images to the Imgur API and I want to implement a progress bar to show users the upload progress. I found some guidance in this thread, but it seems to display only 1 and stop working. This is the ...

A custom JSON response object can be generated by handling a NullPointerException

When delving into Spring REST Services, I encountered NullPointerExceptions and their corresponding responses. Due to the lack of specific details/information provided by the NullPointerException (as a Client), I am interested in crafting my own JSON Obje ...

Using jQuery's append function will retrieve external source files within script tags, however, it will not officially render them in the DOM

After including a script with an external source and attempting to parse it using jQuery, the script is downloaded but not loaded into the DOM. This issue persists regardless of which jQuery DOM insertion method I use, such as .append(). Take a look at th ...

I am encountering a 302 error when attempting to sideload images on Imgur using the API

I've been experimenting with sideloading using imgur's API. $.get("http://api.imgur.com/2/upload.json?", { url: www.example.com/blah.jpg },function(response){ var url = response.upload.links.original; var thumb_url = response ...

Retrieving values using jQuery from specific class identities

Could someone help me extract the value from this specific HTML tag? <INPUT id=ctl00_MyTaxonomyFieldID_ctl00_ctl01 class="ms-taxonomy ms-taxonomy-height ms-long" value=MyTaxonomyFieldValue|f0d123d1-ac8c-4a18-bccb-65c9b5ea83af type=hidden> I need to ...

In your experience, what's the most efficient method you've come across for editing tags?

Currently, I am working on implementing a feature that allows users to edit the list of tags displayed next to each link on a website. This includes adding, removing, and modifying tags. I am searching for an efficient way to make this process user-friend ...

What is the process for conducting linting with nodemon?

Is it possible to utilize nodemon for linting my javascript without the use of build tools like gulp or grunt, in order to fully leverage node and npm? Nodemon's output can be piped. I am interested in using this feature for linting the changed file ...

Ways to enhance the appearance of the parent element when the radio button is clicked

Hey there! So, I have a situation where I'm working with two radio buttons and I want to apply certain CSS styles to the parent box (<div>) when a radio button is selected (checked). Here's how I want it to look: box-shadow: 0 0 5px #5cd05 ...

Tips on building a blog using solely index.html, style.css, and script.js files

Looking for inspiration for blog listing pages? Check out some examples like: HubSpot's marketing blog or iGoMoon's blog. I'm trying to figure out where I should start. Should I begin with the first line of code? Or can I import sample code ...

Enhancing the appearance of dropdown menus for WooCommerce Variable products with custom CSS styling

I currently have a Wordpress website with WooCommerce and several variable products. Each product's variation has a dropdown menu that displays different options when clicked. My main concern is how to customize the appearance of these dropdown menus ...

Prevent any future dates from being entered

My Thoughts: <input type="text" class="datepicker" placeholder="DD/MM/YYYY" id="datepicker" ng-model="datepicker" name="datepicker" style="width:100%" tabindex="4" required/>` Controller: `$('#datepicker').datepicker({ format: &a ...

Showing information to several classes using JavaScript

I am currently developing a "Gamebook Engine" that enables users to set a custom username. The user name is extracted from an input element with the id="setUserNameInput" and stored using the function setUserName(). It is then displayed or loaded into an e ...

Tips for Resizing and Reviving Divs with jQuery

I have recently ventured into the world of web development to assist a family member with their website. My knowledge and experience are limited, but I am facing an interesting challenge. I am trying to manipulate certain divs as users scroll down the page ...

"Upon clicking the commandButton with the bootsfaces iconAwesome, an Uncaught TypeError is triggered due to the inability to read the 'id' property

Whenever I click on a b:commandButton with an iconAwesome, the following error occurs: bsf.js.xhtml?ln=bsf:7 Uncaught TypeError: Cannot read property 'id' of nullBsF.ajax.onevent @ bsf.js.xhtml?ln=bsfsendEvent @ jsf.js.xhtml?ln=javax.faces:1 ...

What is the best way to display an international phone number using Angular Material V6?

I've been working on a project that utilizes Angular Material V6. My goal is to display international phone numbers with flags in a Material component text box. After some research online, I came across an npm module that achieved this but it was tail ...