AnsweredAssumed Answered

Custom format popup - attribute is integer, want to display string

Question asked by MollyKFoley on Mar 5, 2018
Latest reply on Mar 6, 2018 by MollyKFoley

I have a field called "OfficialQH" that holds either a 0 or a 1. I want to display those values as "No", or "Yes", respectively. I'm a javascript novice and I have a feeling I'm missing something silly, but this is what I've got. I have been following along with these examples:

PopupTemplate - use functions to set content | ArcGIS API for JavaScript 4.6 

Format info window content | ArcGIS API for JavaScript 3.23 


I'm not sure I'm using "value" in my switch statement correctly. I understand that the key is the field name, the value is what is associated with the key in that record, and the data allows you to access other attributes of that record (I think?). So when {OfficialQH:status} gets hit because a feature was clicked, I expect it to call the status function, pass in key = OfficialQH, value = 1 (or 0 depending on the feature clicked), data = other available attributes of record. Then in the switch statement, it reads the value and assigns the result variable a "Yes" or "No" string, then returns the result to hopefully display in the popup. Is my logic flawed? Am I missing a pesky parentheses or bracket? Is there another way I should be using value/key/data?


        var popup = {
          title: "{StateID}, Point {Point}, Patch {PatchNum}",
          content: "<ul><li>Canopy Deciduous: {CnpyDecid}%</li>" +
                  "<li>Canopy Coniferous: {CnpyConif}%</li>" +
                  "<li>Bare Ground: {BareGround}%</li>" +
                  "<li>Habitat Status: {OfficialQH:status}</li></ul>"
        var featureLayer = new FeatureLayer({
          url: "https://xxx/MapServer/0",
          outFields: ["*"],
          popupTemplate: popup

        featureLayer.refreshInterval = 3;
        status = function (value, key, data) {
            var result = "";

            switch (value) {
              case 1:
                result = "Yes";

              case 0:
                result = "No";

            return result;