Hey all,
I'm trying to configure pops-ups. The following expression works fine.
var formatService = When($datapoint["services_offered"]=='Health_Department/Clinics' , ‘Health Department/Clinics ’)
However, the expression is given below doesn't works.
var formatService = When($datapoint["services_offered"]=='Health_Department/Clinics' & 'Family_Planning_Birth_Control_S', ‘Health Department/Clinics and Family Planning Birth Control Services’)
Can you please share your thought?
& would require both statements to be true, and the second "statement" is just a string of text. Also, it needs to be "&&" in Arcade.
The properly-written version of your statement would be:
When($datapoint["services_offered"]=='Health_Department/Clinics' && $datapoint["services_offered"]=='Family_Planning_Birth_Control_S', ‘Health Department/Clinics and Family Planning Birth Control Services’)
But of course, your field can't be equal to two values, so what you ought to use is "||" to return the value when it matches either statement. Also, consider throwing that field into a variable first, to make your expression more concise.
var svcs = $datapoint["services_offered"]
var formatService = When(svcs == 'Health_Department/Clinics' || svcs =='Family_Planning_Birth_Control_S', ‘Health Department/Clinics and Family Planning Birth Control Services’)
Of course, you could also make use of another function here: Includes. And also, when you are only checking a single statement, you can use Iif as well, though either will work. Both require a default value provided at the end, if I'm not mistaken.
var svcs = $datapoint["services_offered"]
var matches = [
'Health_Department/Clinics',
'Family_Planning_Birth_Control_S'
]
var formatService = When(Includes(matches, svcs), 'Health Department / Clinics and Family Planning Birth Control Services', '')
But then, that output string really doesn't make sense if an either/or match.
You'll probably need to provide more information about your data and what you're trying to do.
Thanks, Josh for your comment. I really appreciate your help. I'm trying to configure pop-ups on the dashboard. The full code is following-
var formatService = When($datapoint["services_offered"]=='Health_Department/Clinics','Health Department/Clinics',$datapoint["services_offered"]=='Violence_Neglect_&_Abuse_Relate', 'Violence, Neglect, and Abuse Related Services', $datapoint["services_offered"]=='Healthcare_Services', 'Healthcare Services', $datapoint["services_offered"]=='Financial_Food_Clothing_&_Housi', 'Financial, Food, Clothing, and Housing Services', $datapoint["services_offered"]=='Violence_Neglect_&_Abuse_Relate', 'Violence, Neglect, and Abuse Related Services', $datapoint["services_offered"]=='Educational_Resources', 'Educational Resources', $datapoint["services_offered"]=='Pregnancy_Crisis_Services', 'Pregnancy Crisis Services', $datapoint["services_offered"]=='Child_Care_&_Day_Care_Services_', 'Public Child Care & Day Care Services', $datapoint["services_offered"]=='Counseling_&_Mental_Health_Serv', 'Counseling & Mental Health Services', $datapoint["services_offered"]=='Adoption_Choices', 'Adoption Choices', $datapoint["services_offered"]=='Crisis_Emergency_Services', 'Crisis Emergency Services', $datapoint["services_offered"]=='Employment_Services', 'Employment Services', $datapoint["services_offered"]=='Family_Planning_Birth_Control_S', 'Family Planning Birth Control Services', $datapoint["services_offered"]=='Health_Related_Other_Resources', 'Other Health Related Resources', $datapoint["services_offered"]=='Legal_Services', 'Legal Services', $datapoint["services_offered"]=='Pregnancy_Crisis_Services', 'Crisis Pregnancy Services', $datapoint["services_offered"]=='Special_Needs', 'Special Needs', $datapoint["services_offered"]=='Substance_Abuse_Support_&_Treat', 'Substance Abuse Support & Treatment Services', $datapoint["services_offered"]=='Transportation', 'Transportation', defaultValue)
var formatName = IIf(DomainName($datapoint,"agency_or_facility_name")=='Other', $datapoint["agency_or_facility_name_other"], DomainName($datapoint,"agency_or_facility_name"))
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
formatService: formatService,
formatName: formatName
}
}
This code is working fine. However, I need to show two services for some areas. I tried different ways including your suggestion. But I haven't come up with any solution yet.
I'm trying to add another service in pop-ups (see red arrow on the image)
I really appreciate your help.
So, what does the data actually look like when there are two?
It can't execute arcade scripts.
No no, I mean what does the actual row of the source data table look like? How can there be two values in a single field?
The data come from a hosted layer generated by a survey through survey123. In that survey, one question was about which services are available. There are 7/8 options for that question.
For example, there are three services here.
My issue is solved. I want to say thank you, Josh. I really appreciate your time.
No problem! I was writing up a possible expression for you to use that makes use of Split and Decode:
var svcs = $datapoint['services_offered']
// Split up the value
var svc_array = Split(svcs, ',')
// Iterate over each service
for (var s in svc_array){
// Strip out "_"
svc_array[s] = Replace(svc_array[s], '_', ' ')
// Format remaining values
svc_array[s] = Decode(
svc_array[s],
'Violence Neglect & Abuse Relate', 'Violence, Neglect, and Abuse Related Services',
'Financial Food Clothing & Housi', 'Financial, Food, Clothing, and Housing Services',
'Counseling & Mental Health Serv', 'Counseling & Mental Health Services',
'Family Planning Birth Control S', 'Family Planning Birth Control Services',
'Health_Related_Other_Resources', 'Other Health Related Resources',
'Substance Abuse Support & Treat', 'Substance Abuse Support & Treatment Services',
svc_array[s]
)
}
// Merge values back into single string
return Concatenate(svc_array, ', ')
Testing it out on a sample value like Family_Planning_Birth_Control_S,Health_Department/Clinics, I get the following response: