Select to view content in your preferred language

Arcade Expression to break up field by identifer for pop-up

819
5
Jump to solution
05-03-2023 09:49 AM
Labels (1)
KevinDurkee
Emerging Contributor

Hi 

I have a field (contactinfo) in a dataset that has a large amount of data in it and I am hoping to Split it via an arcade expression in a pop up. I thought the best way to split them in the expression would be by the comma.

The data in the field is shown below:

Owner ID: 0, CLIENT_TYPE_CODE: C, NAME1: JAMES HAMMERS INC , NAME2: , STREET1: 5783 TURNSTONE DR, STREET2: , CITY: LANGSVILLE, PROV_STATE_CODE: BC, COUNTRY_CODE: CAN, POSTAL_ZIP: V0N3A7, PHONE1: , PHONE2: , FAX: , CLIENT_NET_ADDR: , CONTACT_NAME: , CONTACT_PHONE1: , CONTACT_PHONE2: , CONTACT_FAX: , CONTACT_NET_ADDR:

I've tried something like this Split($feature.contact_info) if ,= true, however I think I'm getting a  syntax error. 

I'm fairly new to arcade, feel like this is probably quite simple and I'm just missing it.

Thanks for any help!

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The use can use that in an expression like this to show only the values that aren't blank

 

var data = 'Owner ID: 0, CLIENT_TYPE_CODE: C, NAME1: JAMES HAMMERS INC , NAME2: , STREET1: 5783 TURNSTONE DR, STREET2: , CITY: LANGSVILLE, PROV_STATE_CODE: BC, COUNTRY_CODE: CAN, POSTAL_ZIP: V0N3A7, PHONE1: , PHONE2: , FAX: , CLIENT_NET_ADDR: , CONTACT_NAME: , CONTACT_PHONE1: , CONTACT_PHONE2: , CONTACT_FAX: , CONTACT_NET_ADDR:';

var theArray = Split(data,',');
var output = '';
for (var index in theArray) {
  var theInfo = Split(theArray[index],':');
  if (!IsEmpty(Trim(theInfo[1]))) output += `${Trim(theInfo[0])}: ${theInfo[1]}${TextFormatting.NewLine}`;
}
return output;

output.png

 

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

The syntax for the Split function is Split(inputText, separatorText, limit?, removeEmpty?). Your code should be

var theArray = Split($feature.contact_info, ',');

 

KenBuja
MVP Esteemed Contributor

The use can use that in an expression like this to show only the values that aren't blank

 

var data = 'Owner ID: 0, CLIENT_TYPE_CODE: C, NAME1: JAMES HAMMERS INC , NAME2: , STREET1: 5783 TURNSTONE DR, STREET2: , CITY: LANGSVILLE, PROV_STATE_CODE: BC, COUNTRY_CODE: CAN, POSTAL_ZIP: V0N3A7, PHONE1: , PHONE2: , FAX: , CLIENT_NET_ADDR: , CONTACT_NAME: , CONTACT_PHONE1: , CONTACT_PHONE2: , CONTACT_FAX: , CONTACT_NET_ADDR:';

var theArray = Split(data,',');
var output = '';
for (var index in theArray) {
  var theInfo = Split(theArray[index],':');
  if (!IsEmpty(Trim(theInfo[1]))) output += `${Trim(theInfo[0])}: ${theInfo[1]}${TextFormatting.NewLine}`;
}
return output;

output.png

 

0 Kudos
KevinDurkee
Emerging Contributor

Hi Ken, appreciate the quick response. I tried the code and just received an empty box. Do I need to put a sort by for each identifier so that it knows for example OWNER ID: 0 is split into a sperate faux field?

KevinDurkee_0-1683134385366.png

Or do I need a separate expression for each line I'd like to see, as seen below?

KevinDurkee_1-1683134894139.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You can remove the Field element, then add in a Text element. Inside the Text element editor, click the Field dropdown and add your Expression. The Configure Popups should look something like this

popup0.png

0 Kudos
KevinDurkee
Emerging Contributor

Really appreciate your help, yes this works perfectly. Thank you!

0 Kudos