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

Change the color of a c3js chart when it loads

I have been searching for a way to customize the color of a scatter chart's plot, and I came across an example that uses d3 code within the chart http://jsfiddle.net/ot19Lyt8/9/ onmouseover: function (d) { d3.select(d3.selectAll("circle ...

Change an XML file to a JSON dump in Python

Hello there! I am looking to convert an XML file into a JSON dump. I have already attempted the following: for i in cNodes[0].getElementsByTagName("person"): self.userName = i.getElementsByTagName("login")[0].childNodes[0].toxml() self.use ...

Best practices for outputting objects within an array using jQuery and JavaScript

Seeking guidance. I am utilizing a unique jQuery calendar plugin (which appears to be uncommon!) that is fully initialized with JS, without any HTML. In order to include events, you must define each event as an object inside an array: events: [ { ...

Choose an XPath selector that targets a list item within a specific div element

Currently, I am using selenium to conduct testing on a website. I have employed an XPath selector in order to locate a specific item within the HTML structure: <div id="boundlist-1051" class="x-boundlist list_cfg_cls x-boundlist-floating x-layer x-boun ...

Guidelines for passing a value to a method within a method using JavaScript

I am currently exploring how jQuery can be used to select an element, retrieve an attribute, and assign it a new value. While I have successfully managed to select the element and extract the attribute, I am facing difficulty in setting the attribute using ...

Tips for accessing information from an Angular Resource promise

I am currently facing an issue when trying to read data from an angular promise that was returned. Before, I had the following code: var data = category.get({id:userid}); Later, I realized that the data being returned was an unresolved promise. So, I ma ...

I am currently working with an input element that is set to hidden. I am trying to change its type to text using JavaScript, but I can't seem to figure out how to do it or if it is even possible

I'm stuck trying to change the type of an input element from hidden to text using JavaScript. I can't seem to figure out if it's even possible. Can someone please help me with this? Thanks! ...

Referencing another component in StyledComponents

I'm looking to modify the properties of my parent component's :after selector whenever the child element is focused. It seemed straightforward at first, but for some reason, I just can't seem to make it work. Here's a glimpse of my comp ...

Angular2's hidden feature isn't functioning properly

There is a common suggestion to use *ngIf better than [hidden] but in my scenario, I want to keep the element in the DOM without it being visible. In my component.html file, I have: <article #articleId id="bodyArticle" [hidden]="isClicked"></art ...

Using async await in a React component causes a syntax error

Struggling with setting up a basic react app using hapi.js on the server-side, I am diving into the world of webpack and babel as a newcomer. Here's a glimpse at my React component App.jsx: import React from 'react'; export default class A ...

Utilizing jQuery to extract the value of a selected list item on click

I have been working on creating a list of items from JSON data and am facing an issue with retrieving the 'data-value' attribute of the clicked item. Here is my current code: const target = $('#list'); target.empty(); for (let i = 0 ...

Creating a customized Axios instance in Typescript can provide more flexibility and control over

I am looking to create an API with a customizable instance using Axios. Ideally, I want to be able to use a basic instance like this: api.get("url")... In addition, I would like to have the flexibility to add dynamic bodies and access them using something ...

Would you like to learn how to set an auto-play video as the background in a webpage section, similar to the one found on http://www8.hp.com/in/en/home.html?

I was browsing the HP-India website and noticed they have a cool autoplay video in the background of a section below the header. I would love to recreate something similar on my own website. Any tips on how to achieve this? ...

Tips for efficiently indexing JSON data in PostgreSQL version 9.2

Is there a method for indexing JSON data in PostgreSQL 9.2? Here is an example of the data format: [ {"key" : "k1", "value" : "v1"}, {"key" : "k2", "value" : "v2"} ] If I want to index all the keys, how would I go about doing that? Thank you. ...

Ways to effectively conceal an HTML div element with CSS or JavaScript

Is there a way to hide the div element that is nested inside a bootstraps radio or checkbox container using jquery? I'm unable to upload an image, but here is a preview: http://prntscr.com/6wrk2m <style> .my-radio{ border: 1px solid #F0F; } &l ...

When using Multer for file upload, the req.body returns as an empty object while req.file is undefined

I previously shared a problem I encountered while using multer for file upload in the MERN stack. Despite my attempts, I have not yet been able to resolve it. In my app, I am using both body-parser and multer. Here is the order of code in my index.js file: ...

When attempting to use Ajax, the operation fails; however, if I directly access the URL,

When using firebug, I attempted to make the following AJAX call: var rootUrl = 'http://172.24.105.22:8080/geoserver/Chennai_Sub/ows'; var defaultParameters = { service: 'WFS', version: '1.0.0', request: 'Get ...

Improving the display of events with fullcalendar using ajax requests

I have integrated the fullcalendar plugin from GitHub into my project. I am looking to implement a feature where I can retrieve more events from multiple server-side URLs through Ajax requests. Currently, the initial event retrieval is functioning proper ...

Extra Pathway

Having trouble adding a second route to the /privacy page. The error "Cannot GET /privacy.html" keeps popping up. Any suggestions? This code seems to be failing to display the privacy.html content app.get('/privacy', function(req, res) { res.s ...

Is there a way in AngularJS utilizing ui-router to retrieve the ngResource error from $stateChangeError when a request fails in the resolve section of a state?

Check out this plunker where I am facing an issue: http://plnkr.co/edit/vdctsTcMq4nD1xpUl3pu The problem is that the $resource promise is being rejected due to a request failure (404 error). I am aware that I can handle the error within the resolve block ...