Arcade Pop-Up. First two functions work, while third fails.

460
4
Jump to solution
08-26-2021 12:11 PM
JohnDriessen
New Contributor III

Hi folks, thanks for any assistance you can offer.  Being somewhat new to Arcade I'm sure this is an amateur mistake.

Problem:  The first two lines of code work as they should.  An IFF statement to remove blank fields, followed by a prefix and suffix added to a field, creating a hyperlink.

Some of the fields (in this case ASBUILTS) need to be removed.  I've parsed those out and have a list of 30 which the find and replace with "" will run on.

//works

var ASBUILT = IIF(isEmpty($feature.AsBuiltFileName), "",
"https://asbuilts.ci.missoula.mt.us/water/" + $feature.AsBuiltFileName + ".pdf")

Replace(ASBUILT,"https://asbuilts.ci.missoula.mt.us/water/HH2-A.pdf","")

//doesn't work

var ASBUILT = IIF(isEmpty($feature.AsBuiltFileName), "",
"https://asbuilts.ci.missoula.mt.us/water/" + $feature.AsBuiltFileName + ".pdf")

Replace(ASBUILT,"https://asbuilts.ci.missoula.mt.us/water/HH2-A.pdf","")
Replace(ASBUILT,"https://asbuilts.ci.missoula.mt.us/water/010-A.pdf","")

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Frequent Contributor

If I'm understanding this correctly, you have a list of 30 values that should be removed?

While I can't be sure exactly why your code isn't working, you should know that the Replace function returns a string. Without assigning the results of that function to a variable, Arcade is going to treat that as having an implicit return. Meaning, it will read that function as providing the output of your full expression. This applies specifically when it's the final line of your expression.

In any case, those multiple Replace functions won't be doing what you think they will, and it's not the best approach.

Try something like this:

  1. Establish a list of values to exclude
  2. Check if your field is empty
  3. If it is not empty, check if it's in the "excluded" list
  4. If it's not in that list, assemble the string and return it.

This has the benefit of not needing to do a series of find/replace functions when the field is empty. If the field is empty, or it's in the exclude list, the expression simply stops there and doesn't return anything. Here's the code:

// List of items to exclude
var excluded = [
    'a',
    'list',
    'of',
    'values',
    'to',
    'exclude'
]

var asbuilt = $feature.AsBuiltFileName

var urlstart = 'https://asbuilts.ci.missoula.mt.us/water/'

// Check if not empty
if(!IsEmpty(asbuilt)){
    // Check if excluded
    if(!Includes(excluded, asbuilt)){
        return `${urlstart + asbuilt}.pdf`
    }
}

 

Here's me testing it against a couple of static values and a null value.

jcarlson_0-1630008307639.png

jcarlson_1-1630008337571.pngjcarlson_2-1630008353720.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Frequent Contributor

If I'm understanding this correctly, you have a list of 30 values that should be removed?

While I can't be sure exactly why your code isn't working, you should know that the Replace function returns a string. Without assigning the results of that function to a variable, Arcade is going to treat that as having an implicit return. Meaning, it will read that function as providing the output of your full expression. This applies specifically when it's the final line of your expression.

In any case, those multiple Replace functions won't be doing what you think they will, and it's not the best approach.

Try something like this:

  1. Establish a list of values to exclude
  2. Check if your field is empty
  3. If it is not empty, check if it's in the "excluded" list
  4. If it's not in that list, assemble the string and return it.

This has the benefit of not needing to do a series of find/replace functions when the field is empty. If the field is empty, or it's in the exclude list, the expression simply stops there and doesn't return anything. Here's the code:

// List of items to exclude
var excluded = [
    'a',
    'list',
    'of',
    'values',
    'to',
    'exclude'
]

var asbuilt = $feature.AsBuiltFileName

var urlstart = 'https://asbuilts.ci.missoula.mt.us/water/'

// Check if not empty
if(!IsEmpty(asbuilt)){
    // Check if excluded
    if(!Includes(excluded, asbuilt)){
        return `${urlstart + asbuilt}.pdf`
    }
}

 

Here's me testing it against a couple of static values and a null value.

jcarlson_0-1630008307639.png

jcarlson_1-1630008337571.pngjcarlson_2-1630008353720.png

 

- Josh Carlson
Kendall County GIS
JohnDriessen
New Contributor III

Josh thank you so much your solution worked seamlessly!  I may have to reach-out to you later today with yet another quandary regarding displaying related table attribute fields within a pop-up attribute expression.  If you have a favorite brewery nearby I'd be happy to buy you a beer.

0 Kudos
jcarlson
MVP Frequent Contributor

You're very welcome! I'll keep an eye out for future posts. Related attributes in a popup is a popular topic here, so I'd be surprised if there wasn't something on here already that might help you there.

Cheers! :clinking_beer_mugs:

- Josh Carlson
Kendall County GIS
0 Kudos
JohnDriessen
New Contributor III

Josh want another one?...  When attempting to populate a related record within a pop-up, in this case sewer ditchcard hyperlinks I know that I'm missing a section of code which specifies the field within the related table to populate from.

It might be worth noting FeatureSetByRelationshipName function is for one reason or another not available so I'm calling the table from $map.

 

1. var ServiceType = $feature;
2. if (Find('Sanitary', ServiceType, 0) > 0);
3. var Hyperlink = 'https://asbuilts.ci.missoula.mt.us/scards/' + FeatureSetByName($map,"Ditch Card Links - ConnectionTEST - Connection Data Table") MISSING FIELD FUNCTION + '.pdf'
4. return Hyperlink

JohnDriessen_0-1630365289359.pngJohnDriessen_1-1630365331774.png

JohnDriessen_2-1630365369551.png

 

 

0 Kudos