I am doing a Cityworks and Problem Reporter (AGOL) integration. I have set up two-way communication between both services but when a comment is added in Cityworks it populates the comment field in the public feature layer of Problem Reporter with a lot of extra information that is not needed.
If I need to add a new field, Comments_public for example, I'm okay with that. I would like for only the actual comment to show up in the comment field instead of listing the employee, date and time as it is showing currently.
I was able to do the above in excel using the formula: =RIGHT(A2,LEN(A2)-SEARCH(":",A2)-9)
However, I have yet to figured out a way to do it using Arcade. I found a formula that got me close (shown below) but unfortunately I got everything up to the first " :" (By Lukas, Ari 1/11/2022 3) instead.
var array = Split($feature.StaffComments, ":");
if (Count(array) ==2) {
return Trim(array[1]);
}
else {
return Trim(array[0]);
}
Any assistance would be greatly appreciated!
Solved! Go to Solution.
You can do this pretty simply with Pop, which will return the last item in an array, regardless of its length.
var arr = Split($feature.StaffComments, ":");
return Pop(arr)
Your example comment has four components when split by ":"
You code should be
var array = Split($feature.StaffComments, ":");
if (Count(array) == 4) {
return Trim(array[3]);
}
else {
return Trim(array[0]);
}
You can do this pretty simply with Pop, which will return the last item in an array, regardless of its length.
var arr = Split($feature.StaffComments, ":");
return Pop(arr)
I'm trying to use the Pop method to return "Environmental Protection" in my pop-up but instead it returns "EP". Can someone please let me know why the text before the dash is being returned?
Are you using domains for this field? If so, you'd have to use DomainCode inside the Split function.
Thanks for bringing that to my attention! I made a copy of my original data and shared that as a web layer to AGO. The original data contains coded values and unfortunately the copy did not write the text to my new field as I assumed it had. So as it stands there is nothing in the field to split. My plan is to use a series of if statements to populate the data I need unless there is a simpler way.