Select to view content in your preferred language

attribute coded value shown as 'undefined' in infoWindow

4007
12
10-19-2012 10:06 AM
deleted-user-ugCMpXci8bn5
Deactivated User
Hello,

I have a tabbed infoWindow in my web app (using v3.2, Server10.0).  The field in question uses a coded value (integers, corresponding to strings).
The problem is that this field is shown as 'undefined' in the infoWindow, rather than either the range or dmoain value.
This tabbed infoWindow is built based on this example:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm

There is a fair amount of code involved in the tabbed structure..I'll post what I think is the most relevant below..

ideas? Thanks! // Jason

Identify Task and Params:
    function initFunctionality(map) 
    {
        dojo.connect(map, "onClick", doIdentify);

        identifyTask = new esri.tasks.IdentifyTask("http://" + mapDomain + "/ArcGIS/rest/services/mapServer");

        identifyParams = new esri.tasks.IdentifyParameters();
        identifyParams.tolerance = 10;
        identifyParams.returnGeometry = true;
        identifyParams.layerIds = ssLayer.visibleLayers;
        identifyParams.layerOption = "all";
        identifyParams.width = map.width;
        identifyParams.height = map.height;

        map.infoWindow.resize(415, 200);
        map.infoWindow.setContent("");
        map.infoWindow.setTitle("");
        map.infoWindow.setContent(dijit.byId("tabs").domNode);
        map.infoWindow.setTitle("Identify Results");
}



infoWindow layout:
               
                    if ((layerResults.features.length > 0) && (orgOn != 0)) {
     dijit.byId("tabs").selectChild("orgTab");
                    content = "<i>Total features returned: " + layerResults.features.length + "</i>";
                    content += "<table border='1'><tr><th>Name</th><th>Address</th><th>BIN</th><th>Category</th></tr>";
                    for (var i = 0, il = layerResults.features.length; i < il; i++) {
                        content += "<tr><td>" + layerResults.features.attributes['Name'] + "</td>"; // works fine
                        content += "<td>" + layerResults.features.attributes['Address'] + "</td>"; // works fine
                        content += "<td>" + layerResults.features.attributes['CodedValue'] + "</td>"; 
                        // this line returns 'undefined' /// 
                             
                    }
                    content += "</tr></table>";

}
0 Kudos
12 Replies
deleted-user-ugCMpXci8bn5
Deactivated User
Hello again..I still haven
't figured this out..I can get at least the integer value when I refer to the same attribute in a content pane, but I still get 'undefined' when attempting to print the same attribute value to screen...any ideas? Thanks!
0 Kudos
__Rich_
Deactivated User

infoWindow layout:
               
                    if ((layerResults.features.length > 0) && (orgOn != 0)) {
     dijit.byId("tabs").selectChild("orgTab");
                    content = "<i>Total features returned: " + layerResults.features.length + "</i>";
                    content += "<table border='1'><tr><th>Name</th><th>Address</th><th>BIN</th><th>Category</th></tr>";
                    for (var i = 0, il = layerResults.features.length; i < il; i++) {
                        content += "<tr><td>" + layerResults.features.attributes['Name'] + "</td>"; // works fine
                        content += "<td>" + layerResults.features.attributes['Address'] + "</td>"; // works fine
                        content += "<td>" + layerResults.features.attributes['CodedValue'] + "</td>"; 
                        // this line returns 'undefined' /// 
                             
                    }
                    content += "</tr></table>";

}


Just had a quick glance...look at the way you're trying to access the value in the attributes object, what value are you really using as the key?
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
I am not sure what you mean...obviously I do not actually have 'coded value' in my code; I have the name of that attribute field, in the exact same way as I have it written in my content function, but there I get the integer value, here I get 'undefined'...maybe I am missing the point of your hint?
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
I wrote in 'CodedValue' in place of 'Category' just to show where the coded value was..In the code it is 'Category', one of the fields for that layer..I have almost the exact same code elsewhere , which prints the info to a content pane without any problems.  Is that what you mean?
0 Kudos
__Rich_
Deactivated User
I wrote in 'CodedValue' in place of 'Category' just to show where the coded value was..In the code it is 'Category', one of the fields for that layer..I have almost the exact same code elsewhere , which prints the info to a content pane without any problems.  Is that what you mean?

So the code you posted isn't the code you use?  (I'm confused!)

Could you put this in your code (just inside that for loop will be fine) then post the output:
//Assumes you're using an up-to-date browser!
console.log(Object.keys(layerResults.features.attributes));
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
that code gives : "["OBJECTID","SHAPE" ,"Name","Address","City"......] in the console...for the Category attribute, 'Program Category'(the alias) is given..I tried replacing the text with the alias but this does not work.
0 Kudos
__Rich_
Deactivated User
...and if you stick a breakpoint on that line and then add a watch on layerResults.features.attributes what do you see?  (expand it then screenshot it)
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
I was actually able to get this to work using the alias (although I'm not sure why that worked..?)...I was trying to use a lookup function to replace the int with a string, but when I removed this and replaced the field name with the field alias, it worked...thanks for help.
I am having a somewhat similar issue with another set of field names meant to be printed to a content pane.  I tried that console message you gave above, and the only return was 'Site_name' (the displayFieldName of the field), with nor reference to my desired field....In this example I am getting 'undefined' for every field except for the displayFieldName......the alsias and field name are the same in this case, so that isn't the issue...when I 'watch' this var in Firebug all it says next to it is 'undefined'...thoughts?
0 Kudos
__Rich_
Deactivated User
I was actually able to get this to work using the alias (although I'm not sure why that worked..?)...I was trying to use a lookup function to replace the int with a string, but when I removed this and replaced the field name with the field alias, it worked...thanks for help.

JavaScript doesn't care about whether or not it's an ESRI alias or not, it's just an object with named properties (associative array if you want to Google it) and you access those properties with their single, unique, key.


I am having a somewhat similar issue with another set of field names meant to be printed to a content pane.  I tried that console message you gave above, and the only return was 'Site_name' (the displayFieldName of the field), with nor reference to my desired field....In this example I am getting 'undefined' for every field except for the displayFieldName......the alsias and field name are the same in this case, so that isn't the issue...when I 'watch' this var in Firebug all it says next to it is 'undefined'...thoughts?

Well, the only attribute for the features is called "Site_name" there are no others.

When you watch *which* variable?

(sounds like time for a new thread)
0 Kudos