Variable in Javascript file causing return value to be 'undefined'

I have encountered an issue with my JavaScript file. It is extracting data from a SharePoint list and displaying it on an HTML page, but one of the fields appears as 'undefined' even though I defined it initially.

The problematic variable is 'var txtfurtherinfo ="";'. Can someone assist with this? The JavaScript code below is responsible for fetching device information...

function getDeviceDetails() {
var txtTitle = "";
var txtName = "";
var txtOverview = "";
var txtAccessories = "";
var txtDevicetype = "";
var txtTypicalDeviceUsage ="";
var txtKnownSystemIssues ="";
var txtTrafficlight = "";
var imgDevicePicture = "";
var tempLCS2 = "";
var txtfurtherinfo ="";
var HTML = "<h3>Desktop</h3>";
var Laptop = "Y"
var Tabs="Y" 

var query = "http://example.com/sites/it/ITInfrastructure/_vti_bin/listdata.svc/Devices?$expand=Priority&$filter=Id eq " + window.DeviceId + "";

var call = $.ajax({
        url: query,
        type: "GET",
        dataType: "json",
        headers: {
            Accept: "application/json;odata=verbose"
        }       
    });

call.done(function (data,textStatus, jqXHR){
$.each(data.d.results, function(index, item) {
        var tempID = item.Id;
        var NameofDevice = item.Title;
        var tempTitle = item.Title;
        var DeviceOverView = item.Description;
        var AccessDetails = item.Accessories;
        var DeviceKind = item.DevicetypeValue;
        var Usage = item.TypicalUsage;
        var DevicePriority = item.PriorityValue;
        var DeviceImage = item.DeviceImage;
        var DeviceInformation = item.furtherinfo;

        // Data extraction and formatting
        txtTitle = "<p>" + NameofDevice + "<p>"; 
        txtName = "<p>" + NameofDevice + "</p>" +  DeviceKind + "</p>";
        txtOverview = "<p>" + DeviceOverView + "</p>";
        txtAccessories = "<p>" + AccessDetails + "</p>";  
        txtDevicetype = "<p>" + DeviceKind  + "</p>";
        txtTypicalDeviceUsage = "<p>" + Usage + "</p>";
        txtTrafficlight = "<p>" + DevicePriority + "</p>";
        txtfurtherinfo ="<p>" + DeviceInformation +  "</p>";
        imgDevicePicture = "<img src='" + DeviceImage + "'>";

    });
    $('#devicedetails').append($(txtTitle));  
    $('#deviceoverview').append($(txtOverview));
    $('#devicetitle').append($(txtTitle));
    $('devicename').append(txtName);
    $('#devicekind').append(txtDevicetype);
    $('#deviceacc').append(txtAccessories);
    $('#deviceuse').append(txtTypicalDeviceUsage);
    $('#devicestatus').append(txtTrafficlight);
    $('#furtherinfo').append(txtfurtherinfo);
    $('#imageContainer').append("<img src='/sites/IT/ITInfrastructure/SiteAssets/"+txtTrafficlight.replace(/<[^>]*>/g, '')+".png' />");
    $('.deviceimage').append(imgDevicePicture); 
});

call.fail(function (jqXHR,textStatus,errorThrown){
    alert("Error retrieving data: " + jqXHR.responseText);
});
}

Answer №1

In many cases, encountering 'undefined' in JavaScript occurs when attempting to retrieve data that is not specified within the current scope. It appears that your item variable does not possess a member-variable named "furtherinfo". By referring to the naming conventions of other member-variables, it may be labeled as "FurtherInfo", "furtherInfo", or some variation thereof.

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

How can I transfer data to a different component in Angular 11 that is not directly related?

Within the home component, there is a line that reads ...<app-root [message]="hii"> which opens the app-root component. The app-root component has an @input and {{message}} in the HTML is functioning properly. However, instead of opening t ...

Is there a way to change the color of a specific tab without affecting the content within it

I am attempting to change the color of an individual tab using jQuery. However, when I set the background attribute in CSS, it colors the entire background instead. What specific property should I be setting to only change the color of the tab itself? ...

Storing and Retrieving Cookies for User Authentication in a Flutter Application

I am currently working on developing a platform where, upon logging in, a token is created and stored in the cookie. While I have successfully implemented a route that stores the cookie using Node.js (verified in Postman), I encounter issues when attemptin ...

Converting Java objects to JSON and reversing JSON back to objects in a Spring Boot application with Redis

I'm currently working with SpringBoot and Redis. My goal is to serialize a UserDO object into JSON, store it in Redis, retrieve the JSON data, and then deserialize it back into a UserDO object. public class UserDO { String name; int age; ...

Leveraging nested objects within React state

A React child cannot be an object. If you intended to render a collection of children, utilize an array Encountering the error mentioned above has left me puzzled regarding its restrictions. Below is the code where I am facing this issue. It includes an o ...

Having trouble triggering the button with querySelector in Angular

I have a dynamic page where I need to click on a button. I tried the code below, but it is not working and not showing any alert. However, if we use the same code in the browser console, it executes and shows an alert. Can someone please suggest how to r ...

What is the best way to incorporate a mongoose model into another model?

I have two different models that I am working with. In the user model, I want to include an array of Requests, and in the Request Model, I want to have User as an attribute (without including the password). How can I achieve this? var userSchema = new S ...

Creating getter and setter functions for an input field model property in Angular

I need help creating getter and setter methods for an input field property. Here is my attempted code: import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', st ...

AngularJS's ScrollTo function allows users to scroll to a specific

Trying to implement a quick nav that smoothly scrolls to different sections on the page when a link is clicked. Currently using a guide provided by Treehouse for reference. $("#quickNav a").click(function(){ var quickNavId = $(this).attr("href"); ...

Utilize MySQL/Javascript to determine percentages

I'm facing a challenge with an SQL query in Entrinsik's Informer. I need to calculate a percentage using JavaScript on the result, but unfortunately, Informer cannot access data down columns (such as the total for the percentage). Therefore, I ha ...

I encounter an error while attempting to deserialize a JSON string, making it impossible to

I am encountering an issue with the following code snippet: string downloadString = client.DownloadString(serviceurl); List<Player> myDeserializedObjList = (List<Player>)JsonConvert.DeserializeObject(downloadString, typeof(List<Player>)) ...

Scanner (IE5) impact on page load speeds

I have developed an MVC project which is designed as a single-page application (SPA) utilizing knockoutjs and sammy frameworks. The following script is placed in the head section of the page: <script> var startTime = (new Date()).getTime(); </ ...

What discrepancies exist between running npm install on Windows versus Linux operating systems?

Just have a quick question to ask. I've been searching online with no luck. If I were to run npm install on a Windows machine to set up my dependencies, would it be viable to transfer the node_modules directory to a Linux machine and execute my nodej ...

Seeking guidance: I am currently utilizing Python to implement a regular expression in order to extract and categorize sample restaurant sales data from a .pdf file, and then converting it into a JSON

The regular expression being utilized is ^\s*(\d+)\s*(([A-Za-z]+\s*)+)?(\d+)\s+(.+?)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s ...

Incorporating external content to make it easily discoverable by Google for optimal SEO performance

I am currently working on a project that involves loading external content onto a customer's site. Our main goal is to provide the customer with a simple inclusion method, such as a one-line link similar to Doubleclick, without requiring any server-si ...

Posting photos to MongoDB using Node.js and Express

I am currently facing an issue while attempting to upload an image using multer in Node.js. I have configured multer to save the uploaded images in the "upload" directory, and upon form submission, the image is successfully sent to the directory. However, ...

remove all clicks from jQuery queue

I am facing an issue with a click event that triggers other click events, resulting in the addition of elements to the DOM. EDIT: However, upon clicking it multiple times, additional elements are added each time. Checking the jQuery queue confirms that an ...

Guide to making a fully interactive JSONObject

I am facing a small challenge. I have written a code that involves creating objects from JSONObject and adding data to them in a specific structure, as shown below: JSONObject outerObject = new JSONObject(); JSONArray outerArray = new JSONArray(); JSONOb ...

The Add and Update functions of an AngularJS application are malfunctioning in Internet Explorer

Encountered a situation where updates and additions in IE show results in Chrome :D // Extract category object and id from the parent $scope.addNewCategory = function (category, parentId) { $scope.resetError(); category.parentId = par ...

Access various results from a jQuery function

Is there a way to efficiently extract the values of petKeys and employeeKey using the jQuery functions provided below? var whenSelectDateFromCalendar = function () { initKeyValues(); petKeys = ? employeeKey = ? }; var initKeyValues = function ...