Return text after specific character with Arcade

3168
6
Jump to solution
01-12-2022 01:58 PM
AriLukas
Occasional Contributor

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. 

AriLukas_1-1642023589814.png

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!

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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)

jcarlson_0-1642083410703.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

Your example comment has four components when split by ":"

  1. By Lukas, Ari 1/11/2022 3
  2. 52
  3. 42 PM
  4.  TEST COMMENTS

You code should be

var array = Split($feature.StaffComments, ":");
if (Count(array) == 4) {
  return Trim(array[3]);
}
else {
  return Trim(array[0]);
}
jcarlson
MVP Esteemed Contributor

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)

jcarlson_0-1642083410703.png

 

- Josh Carlson
Kendall County GIS
AriLukas
Occasional Contributor

@jcarlson and @KenBuja  both those worked thank you! I'm going with @jcarlson due to it's simplicity. Thank you both again!

0 Kudos
SarahHartholt
Occasional Contributor III

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?

SarahHartholt_0-1659041206491.png

SarahHartholt_2-1659041250867.png

 

SarahHartholt_1-1659041232509.png

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Are you using domains for this field? If so, you'd have to use DomainCode inside the Split function.

 

0 Kudos
SarahHartholt
Occasional Contributor III

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.

SarahHartholt_0-1659103044625.png

SarahHartholt_1-1659103090402.png

 

 

0 Kudos