Thanks for your help, Kristian. I have been able to incorporate the external scripts into my code. Here's one of the scripts in my external file (scripts.ts).
export function getSources() {
return `
var documents = FeatureSetByRelationshipName($feature, "Document");
var result = "";
var cnt = Count(documents);
if (cnt > 0) {
result = cnt + " documents found:";
for (var document in documents) {
result += TextFormatting.NewLine + " - " + document["Title"];
}
} else {
result = "No documents found";
}
return result;
`;
}
And here's how I bring it into my code
import { getSources } from './arcade/scripts'
const regionLayer = new FeatureLayer({
url: '...',
popupTemplate: {
title: 'Documents by region',
content: [
{
type: 'text',
text: [
'{expression/doc-count}'
]
}
],
expressionInfos: [
{
name: 'doc-count',
title: 'Document Count',
expression: getSources()
}]
},
outFields: ['*']
});
Now I have a followup question. I'd like to use html formatting in my returned list, using this script.
export function getSourcesList() {
return `
var documents = FeatureSetByRelationshipName($feature, "Document");
var result = "";
var cnt = Count(documents);
if (cnt > 0) {
result = \`There are a total of \${ cnt } documents found: <ul>\`;
for (var document in documents) {
result += \`<li>\${document["Title"]}</li>\`;
}
result += \`</ul>\`;
} else {
result = "No documents found";
}
return result;
`;
}
If I use this script with the ExpressionInfos and the text property, I see the formatting tags.
It looks like I have to use CustomContent for this to appear with the formatting tags, but I'm just getting the entire script returned, not the results of the script.
const contentDocList = new CustomContent({
outFields: ['*'],
creator: (event) => getSourcesList()
});
const regionLayer = new FeatureLayer({
url: '...',
popupTemplate: {
title: 'Documents by region',
content: [
contentDocList
],
outFields: ['*']
});
What's the proper way to do this?