Select to view content in your preferred language

Trouble with null check in Arcade element

333
0
03-06-2024 12:58 PM
ZachBodenner
MVP Regular Contributor

Hello, 

I am trying to build an Arcade element in a polygon layer that will essentially accomplish three things: create some header text, create a table with two rows populated by information from a point layer that intersects the polygon, and create a table by iterating through related records to the points. The logic is: we have parcels (the polygons), and on some parcels are points representing present variances. A point will have some information related to variances on that parcel specifically. Then, there is a table related to the variance point that contains a list of all the variances present at that location (as few as 0, for some reason, to as many as 6 or 7)

 

The issue: Once I get to the third step in the Arcade, I attempt a null check before iterating through the related table. If there are related records (determined using a filter statement), then everything works just fine. If nothing passes through the filter though, the entire Arcade expression fails. I've pulled elements of the Arcade apart and confirmed the issue is related to the for loop. The return is three variables one after another - if I remove the for loop, the other variables will work correctly regardless of whether anything passes through the filter.

 

//set variables. First variable is the unique ID that is shared by the primary and related data. Second variable is calling the related forms as a FeatureSet
var varLoc = FeatureSetByName($map, "PUD Locations")
var varian = first(intersects($feature,varloc))

var vars = FeatureSetByName($map, "PUD Variances")
var uid = varian.GlobalID;

//create a filter statement where the maintenance form GUID = GlobalID
var filterStatement = "PUDVarRel = @uid"

// A maintenance form equals the table run through the filter
var varForm = Filter(vars, filterStatement)

var head = IIF(!isEmpty(varian),`<div style="color:#000;font-size:16px;background-color:#A995E6;padding:5px;"><span style><strong>PUD Variances</strong></span></div>`,`<div style="color:#000;font-size:16px;background-color:#A995E6;padding:5px;"><span style><strong>No PUD Variances</strong></span></div>`)

var loc = IIF(!isEmpty(varian),
          `<table style="width:100%;">
              <tbody>
                  <tr>
                    <td style="background-color:#e1e1e1;width:40%;padding-left:2%">
                        <span><strong>Project Name</strong></span>
                    </td>
                    <td style="background-color:#e1e1e1;width:60%;padding-left:2%">
                        <span>${proper(varian.PJCTNAME)}</span>
                    </td>
                  </tr>
                  <tr>
                      <td style="border-bottom: 1px solid #cccccc;padding-left:2%">
                          <span><strong>Description</strong></span>
                      </td>
                      <td style="border-bottom: 1px solid #cccccc;padding-left:2%">
                          <span>${proper(varian.DESCRPTN)}</span>
                      </td>
                    </tr>
              </tbody>
          </table>
`,'')


// Build the pop-up string by iterating through all related features. Add or subtract new lines in the popupString as needed from the related form.
var popupString
if (isEmpty(varForm)){popupstring = ''}

else if (!isEmpty(varForm))
for (var f in varForm){popupString = 
        `<table style="width:100%;">
                    <tr>
                      <td style="width:40%;background-color:#e1e1e1;padding-left:2%">
                          <span"><strong>PUD Variance Number</strong></span>
                      </td>
                      <td style="width:60%;background-color:#e1e1e1;padding-left:2%">
                          <span">${f.VARYNUMB}</span>
                      </td>
                    </tr>
                    <tr>
                      <td style="padding-left:2%">
                        <span><strong>Variance Date</strong></span>
                      </td>
                      <td style="padding-left:2%">
                        <span>${f.VARYDATE}</span>
                      </td>
                  </tr>
                  <tr>
                      <td style="width:40%;background-color:#e1e1e1;padding-left:2%">
                          <span"><strong>Status</strong></span>
                      </td>
                      <td style="width:60%;background-color:#e1e1e1;padding-left:2%">
                          <span">${f.STATUS}</span>
                      </td>
                    </tr>
                    <tr>
                      <td style="padding-left:2%">
                        <span><strong>PUD</strong></span>
                      </td>
                      <td style="padding-left:2%">
                        <span>${f.VARNCPUD}</span>
                      </td>
                  </tr>
                  <tr>
                      <td style="width:40%;background-color:#e1e1e1;padding-left:2%">
                          <span"><strong>Variance Type</strong></span>
                      </td>
                      <td style="width:60%;background-color:#e1e1e1;padding-left:2%">
                          <span">${f.VARYTYPE}</span>
                      </td>
                  </tr>
              </tbody>
          </table>
            <br>
`
}

return { 
    type : 'text', 
    text :`${head}${loc}${popupString}`
}

 

the goal is that after "var popupstring", if there are no matching filtered records, the resulting variable should just be empty. Here is what a parcel looks like if everything passes through the filters:

 

ZachBodenner_0-1709758620481.png

 

And here is what it looks like if nothing passes:

 

ZachBodenner_1-1709758652947.png

 


What I think should be happening is that I should still be getting the head variable showing up here, displaying "No PUD Variances". 

There are no errors when running the code

Tags (3)
0 Kudos
0 Replies