How to replace "0" field value with text in popup window

631
4
Jump to solution
08-06-2012 01:04 PM
DorotheaKnigge
New Contributor III
Parcel acreage is not always supplied by the Assessors office and will therefore have a "0" value (not null).
I have tried adjusting the function below to work with the "0" value but am not having much success.  Could someone help me?

  deferred.addCallback(function(response) {    
             return dojo.map(response, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if(result.layerName === 'House Numbering'){
            console.log(feature.attributes.OBJECTID);
            var template = new esri.InfoTemplate("", "<b>Parcel Information</b><hr><br />Parcel ID:${PREFIX} <br /> Zoning: ${ZONING} <br /> Acreage: ${ACREAGE:calculateAcre} <br /> Address: ${ADDRESS} <br /> City: ${ZIP_CITY}  <br /> Zip Code: ${ZIP_CODE}");
            feature.setInfoTemplate(template);
     
            }
  
  if(result.layerName === 'General Plan'){
              console.log(feature.attributes.OBJECTID);
              var template = new esri.InfoTemplate("", "<b>General Plan Designation</b><hr><br />General Plan:${GP96} <br /> Description: ${Description}");
              feature.setInfoTemplate(template);
            }
  
             else if (result.layerName === 'General_Plan_Overlays'){
              var template = new esri.InfoTemplate("", "<b>General Plan Overlays</b><hr><br />Overlay: ${GP96}");
              feature.setInfoTemplate(template);
            }
            return feature;
          });
        });

        function calculateAcre(value,key,data){
        return data.ACREAGE == '0' ? data.ACREAGE : 'Not Available';
     
      }
0 Kudos
1 Solution

Accepted Solutions
AndreyLabodin
New Contributor III
after

feature.attributes.layerName = result.layerName;


insert this

if (feature.attributes["Your field name"] == '0') {     feature.attributes["Your field name"] = 'No data'; }


I'm not sure if there will be data type mismatch, but this is the way...

View solution in original post

0 Kudos
4 Replies
AndreyLabodin
New Contributor III
after

feature.attributes.layerName = result.layerName;


insert this

if (feature.attributes["Your field name"] == '0') {     feature.attributes["Your field name"] = 'No data'; }


I'm not sure if there will be data type mismatch, but this is the way...
0 Kudos
__Rich_
Occasional Contributor III
after

feature.attributes.layerName = result.layerName;


insert this

if (feature.attributes["Your field name"] == '0') {
    feature.attributes["Your field name"] = 'No data';
}


I'm not sure if there will be data type mismatch, but this is the way...

As long as nothing else cares about the data type being mutated in this way further down the line, personally I think this is purely a output format question and should not change the underlying data.

Besides, the custom format function should work, I have just modified one of the samples without any issues.

@Dorothea - what's the actual issue you're seeing?  e.g. is your function not being called?  is it returning the wrong value? what's the scope of your code?  etc.

In terms of the method signature, it looks ok, apart from a little efficiency that you could gain from using the attribute's value that's been passed in i.e.
 function calculateAcre(/*string*/attributeValue, /*string*/ attributeName, /*object*/ allAttributes){
        return attributeValue!="0"?attributeValue:"Unknown";
      }

Checking against the value being a string containing zero is ok I guess, since all attributes are sent back from Identify as strings.

Just a couple of little questions on the side, is the acreage value being zero the only indicator that the value has not been supplied or is there something else you could use?  Also is there a situation where an acreage of zero is perfectly valid i.e. it has been supplied by the Assessors Office and the value really is zero?
0 Kudos
DorotheaKnigge
New Contributor III
Thank you for your responses Andrey and Rich; I had pretty much given up on this thread:)

Let me try your suggestions and I will get back to you.

In response to your questions, the situation is purely an output format thing and not a situation of a parcel acreage actually having a zero value .  We don't want the user thinking that their acreage has a zero value when in fact the Assessor simply didn't supply it.

Thank you again, I'll be getting back to you.....Dorothea
0 Kudos
DorotheaKnigge
New Contributor III
Hi Andre,

I have just tried your recomendation and it works!  Now if a user comes across an acreage field with "0" acreage they get the message  "Not Available".


Thank you again!

Dorothea
0 Kudos