AnsweredAssumed Answered

if else statement to retrieve attribute from map service

Question asked by notoriusjackdevtrial on Jul 16, 2018
Latest reply on Jul 23, 2018 by notoriusjackdevtrial

I have a widget that retrieves the values from different external map services but now they call the value attribute in two different ways: value and Pixel Value

below is the part of the code that retrieves the value attribute.


all(promises).then(lang.hitch(this, function (res) {

   let results = [];
   let j = 0;
   res.forEach(lang.hitch(this, function (serviceResults) {
      serviceResults.forEach(function (featuresWithinServiceResults) {

         let peril = layerInfos[j].Peril;
         let layerDisplayName = layerInfos[j].LayerName;

         let value = featuresWithinServiceResults.value;


            layerName: featuresWithinServiceResults.layerName,
            layerDisplayName: layerDisplayName,
            value: value,
            peril: peril



I understand that to retrieve the Pixel Value I need to pass the following instead:

let value = featuresWithinServiceResults.feature.attributes['Pixel Value'];
But I cannot understand how to pass the logic to pick up Pixel Value if value is not present. I have tried with if else logic but I can't make it work. I tried:
if (featuresWithinServiceResults.value == null){
    let value = featuresWithinServiceResults.feature.attributes['Pixel Value'];
    } else {let value = featuresWithinServiceResults.value;
let value = function() {
   if ((featuresWithinServiceResults.value).length > 0) return featuresWithinServiceResults.value;
   else return featuresWithinServiceResults.feature.attributes['Pixel Value'];
What am I doing wrong?