Using Arcade expression to calculate Next ID and send to Survey123

1949
6
Jump to solution
09-19-2019 10:30 AM
deleted-user-y4x_Wbc6LksS
New Contributor II

I have a webmap that displays existing curb ramp points intended for use on an iPad with the Collector app. The popups have a custom url to open Survey123 for the user to fill out an inspection for this curb ramp. However, if the user is inspecting a NEW curb ramp, they collect the point in collector and the popup displays what the asset id (UNITID) should be as the last UNITID value +1 by using an expression (code attached). I want to pass this expression to Survey123....is this possible?

In testing, the popup works correctly showing the ID if it exists, and calculates the next ID if it doesn't. (This does not work if there are multiple assets with no ID, since they would have the same ID, but this is an experiment)

UID Calc Expression {expression/expr7}

var exist_uid = $feature.UNITID

//grab the highest number asset id

var curbramps = Top(OrderBy((FeatureSetByName($map,'Curb Ramps', ['UNITID'], false)), 'UNITID DESC'), 1)

//calculate the last id+1

for (var cr in curbramps) 
var max_uid = Number(Right(cr.UNITID, 5))+1
}

//curb ramp is tagged as CR12345

var new_uid = Concatenate("CR", max_uid, '')

//if the unit id exists, pass the value. if not, pass the last value+1

iif(isEmpty($feature.UNITID), new_uid, $feature.UNITID)
;

Hyperlink to send ID to Survey123

arcgis-survey123://?itemID=a9b85207d13247218d3bb3eb575919f3&field:UNITID={expression/expr7}

Many thanks for your help!!!

0 Kudos
1 Solution

Accepted Solutions
PeterDalrymple
Occasional Contributor

Hi Amber Lauzon‌,

It looks like FeatureSet functions are not supported yet, but are awaiting release?  Are the Arcade FeatureSet functions supported in Collector? seems to reference similar issues with FeatureSet functions in Collector/Survey123. Maybe Peter Klingman‌ can confirm a timeline for release?

View solution in original post

6 Replies
by Anonymous User
Not applicable

Hi Amber Lauzon‌ - 

It is possible to use an Arcade expression in a custom URL scheme with Survey123. Keep using the default expression alias (e.g. {expression/expr7}) in the URL as this is a unique value. I haven't had a chance to test your exact expression yet, but I don't see a reason why it wouldn't work as long as the expression constructs a valid URL. 

Is it currently not passing the correct values into the survey? Not opening the survey? What does the URL look like when launched from a Web Map (should appear in a browser URL bar before opening the survey)?

Hope this helps,

Peter

0 Kudos
deleted-user-y4x_Wbc6LksS
New Contributor II

Thanks for the reply, Peter. Yes, I can pass other expressions successfully. And, I actually have 2 links for the user to select if they want to collect the survey using the app or the web browser. I did this before I realized there is a setting to give the user the choice. I'm not sure if this is the reason....I can test if you think that will fix.

app url

<a href="arcgis-survey123://?itemID=a9b85207d13247218d3bb3eb575919f3&amp;field:UNITID={UNITID}&amp;field:XCOORD={XCOORD}&amp;field:YCOORD={YCOORD}&amp;center={expression/expr0}, {expression/expr1}">

browser url <<edit 9/22/2019, updated &quest >>no effect on correctly passing the next uid

<a href="https://survey123.arcgis.com/share/a9b85207d13247218d3bb3eb575919f3&quest;field:UNITID={UNITID}&amp;field:XCOORD={XCOORD}&amp;field:YCOORD={YCOORD}&amp;center={expression/expr0}, {expression/expr1}">

The url opens the survey and centers correctly using a lat/long expression. I can also pass an expression that converts CR12345 to a number 12345 and that passes correctly using this Number(Right($feature.UNITID, 5))

If I click on a point that has a UNITID, the url has the correct UNITID (yay! I did not check this before). However, if I click on a point that doesn't have a UNITID, the field is blank.

CR12345

https://survey123.arcgis.com/share/a9b85207d13247218d3bb3eb575919f3?field:UNITID=CR12345&field:XCOOR...

NO UNITID

https://survey123.arcgis.com/share/a9b85207d13247218d3bb3eb575919f3?field:UNITID=&field:XCOORD=&fiel...

Thank you for your help!

PeterDalrymple
Occasional Contributor

Hi Amber Lauzon‌,

It looks like FeatureSet functions are not supported yet, but are awaiting release?  Are the Arcade FeatureSet functions supported in Collector? seems to reference similar issues with FeatureSet functions in Collector/Survey123. Maybe Peter Klingman‌ can confirm a timeline for release?

by Anonymous User
Not applicable

Hi Amber Lauzon‌ & Peter Dalrymple‌ - 

Thanks for the posts here. From the Collector App, it definitely seems like we could be running into the above-mentioned limitation (per the link, slated for fix Q1 2020). This limitation should not affect launching the URL from a Web Map in a browser, though.

What happens when you open the Web Map in a browser on your desktop and launch the Survey123 URL (either browser or app) from a feature that does not have a unit ID? Does this populate the field as expected in the URL/Survey123?

Thanks,

Peter

0 Kudos
deleted-user-y4x_Wbc6LksS
New Contributor II

When clicking on a point that does not have a unit id, the url shows collector passing the correct "next value" on my desktop, but Survey123 does not populate the field if the value if it is calculated from the FeatureSet function. 

Thanks for the help and confirmation Peter Klingman‌ andPeter Dalrymple 

I will be excited when this functionality works in 2020 !!!

0 Kudos
by Anonymous User
Not applicable

Hi Amber and Peter,

I finally had the chance to dive into this a little bit more. I configured a pop-up with the following simple FeatureSet expression:

var related_records = FeatureSetByName($datastore,"RelatedRecords")
var firstRecord = first(related_records)
var text_field_relate = firstRecord.TEXTFLDRLT
return text_field_relate

Then, my URL to the survey is: arcgis-survey123://?itemID=<someID>&field:example={expression/expr0}

On my workstation when I launch the URL from the Web Map, the example field populates as expected. You can also open the pop-up and see that the expression returns the field from the first related record as expected. 

In Collector this field does not show in the pop-up, and the URL does not populate the survey. This is as expected per the above posts. 

So, it looks like if you want to user Feature Sets in Web Maps outside of Collector to populate survey responses, this should work as expected right now. 

Hope that helps!

-Peter

0 Kudos