Custom URL from Collector Passing Attribute Values with Special Characters to Survey123

2445
7
Jump to solution
06-17-2019 08:08 AM
MalloryGill
New Contributor III

I have a web map for use in Collector that has a custom URL in the pop-up to launch a Survey123 form. One of the fields that is passed through the custom URL tends to have a lot of values with apostrophes. In the Survey123 form, all the fields populate via the custom URL as expected until a value with an apostrophe is passed through, then the apostrophe does not appear and nothing after that auto-populates. An example is below:

Field One: 

Compton Peak

Field Two:

Mary         <<< This should read "Mary's Rock"

Field Three:

                 <<< This should read "Rock Castle Gorge" 

This behavior only appears on the iPad and Android mobile devices. When tested in the Windows version of the Survey123 application, all the values come through as expected.

0 Kudos
1 Solution

Accepted Solutions
LanceCole
MVP Regular Contributor

Mallory‌, 

You can create custom expressions for use in your Pop-ups using Arcade.  Please see Attribute Expressions in AGOL and the Arcade Function Index.  You can use an expression along the lines of the following in Arcade.  This will replace a apostrophe with "%27%" if it is in the string or just return the original string if not.  This would need to be modified for strings that could contain multiple apostrophe's. 

Var t = $feature.trail_name
IIf (Find("'", t)>0, Replace(t, "'", "%27%"), t)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Then in your hyperlink reference the expression rather than the field: arcgis-survey123://?itemID=abcdefghijklmnopqrstuvwxyz&field:TrailName={expression/expr0}  

Note, the number of the expression "expr0" will be dependent upon your setup.

1) Open the Feature Map in AGOL

2) Select "Configure Pop-up" for the feature you would like to modify

3) Scroll down to the Attributes Expressions and click the ADD button

Attributes Expressions

4) Build the expression something along the lines as below.

Custom Expression

5) This expression will now be available for use in constructing your Pop-up

Custom Attribute Display

View solution in original post

7 Replies
LanceCole
MVP Regular Contributor

Mallory,

When you build the custom url for Survey123, have you tried to encode any strings with an apostrophe as ‘%27’ for the apostrophe, such as “Mary%27s_Rock”?

0 Kudos
MalloryGill
New Contributor III

Hey Lance Cole - I had the same thought, but we're passing through a field name rather than a specific value for the field. So the URL reads arcgis-survey123://?itemID=abcdefghijklmnopqrstuvwxyz&field:TrailName={trail_name} rather than arcgis-survey123://?itemID=abcdefghijklmnopqrstuvwxyz&field:TrailName="Mary's Rock". I couldn't think of any way to add this encoding on a conditional basis anytime an apostrophe comes up in the passed field's value. But I'm definitely open to any ideas or possible workarounds I've missed!


Thanks for your help!

Mallory

0 Kudos
LanceCole
MVP Regular Contributor

Mallory‌, 

You can create custom expressions for use in your Pop-ups using Arcade.  Please see Attribute Expressions in AGOL and the Arcade Function Index.  You can use an expression along the lines of the following in Arcade.  This will replace a apostrophe with "%27%" if it is in the string or just return the original string if not.  This would need to be modified for strings that could contain multiple apostrophe's. 

Var t = $feature.trail_name
IIf (Find("'", t)>0, Replace(t, "'", "%27%"), t)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Then in your hyperlink reference the expression rather than the field: arcgis-survey123://?itemID=abcdefghijklmnopqrstuvwxyz&field:TrailName={expression/expr0}  

Note, the number of the expression "expr0" will be dependent upon your setup.

1) Open the Feature Map in AGOL

2) Select "Configure Pop-up" for the feature you would like to modify

3) Scroll down to the Attributes Expressions and click the ADD button

Attributes Expressions

4) Build the expression something along the lines as below.

Custom Expression

5) This expression will now be available for use in constructing your Pop-up

Custom Attribute Display

MalloryGill
New Contributor III

Lance Colethis looks like exactly what I need - thank you!! I'll give this a go later this week

Thanks for all of your help!

Mallory

0 Kudos
MalloryGill
New Contributor III

Lance Cole- this worked! I had to tweak the arcade expression just a bit, the expression I ended up using is below

Var t = $feature["Trail_Name"]
IIf (Find("'", t)>0, Replace(t, "'", "%27"), t)‍‍‍‍

And a couple Esri quirks I found as well - when using the custom URL link from a web map, the link attempts to encode the % sign that I'm manually inserting above, adding some extra unexpected characters to the Survey123 form, BUT when the link is clicked from Collector, it works exactly as expected.

I also found that this is currently only supported in Collector for iOS devices. For android devices, the Collector app doesn't honor the arcade expression being sent through (yet) and that field just shows up as a blank line. However, the Beta version of Collector for android (also available in the Google Play Store) does support the arcade expression, so the link and resulting population in Survey123 shows the expected result.

Thanks again for all of your help!

Mallory

0 Kudos
AndrewBowne
Occasional Contributor III

Hi all - 2 years later and I am still seeing the same issues with special characters persist in URLs.  I am using FieldMaps instead of Collector and find myself having to encode every special character using Arcade.  This is a laborious task and really should be unnecessary.

 

Anyone have a better workaround?   Anyone at Esri have some insight????

0 Kudos
AustinCanty1
New Contributor III

@IsmaelChivite is there an official solution for passing attributes with special characters to Survey123?

0 Kudos