|
POST
|
When posting code, please use the "Insert/edit code sample" button. It make it easier to read your code and refer to specific lines. There are a couple of things going on with your code. You have to convert the text to a valid date. Your current code will return a null. The Count function works on arrays, not values, which is what's throwing the error. You want to get the running total of differences and calculate the average outside the loop. You'll have to return a FeatureSet in a Data Expression for an Indicator. Most of these were covered in my reply to your previous post. Give this a try var portal_ = Portal("https://arcgis.com");
var fs = FeatureSetByPortalItem(portal_, "Item ID", 0, ["*"], false);
function StringToDate(input) {
var arr = Split(input, "/");
return Date(arr[2], arr[0] - 1, arr[1]);
}
var total;
for (var f in fs) {
var date_Applied = f["Applied_Date"];
var date_Issued = f["Issued_Date"];
var startDate = DateOnly(StringToDate(date_Applied));
var endDate = DateOnly(StringToDate(date_Issued));
var differences = DateDiff(startDate, endDate, "days");
total += Sum(differences);
}
var totalrows = Count(fs);
var avg = iif(totalrows == 0, 0, Floor(total / totalrows))
return FeatureSet(
{
fields: [{ name: "Average", type: "esriFieldTypeInteger" }],
features: [{ attributes: { Days: avg } }]
}
);
... View more
10-08-2025
07:00 AM
|
1
|
2
|
1299
|
|
POST
|
When building the date, just insert a variable for the year var time = Now();
var time3 = Text(Now(), "MMMM DD, YYYY");
var thisYear = Year(Now());
if (time >= Date(thisYear, 7, 1) && time < Date(thisYear, 8, 1)) {
return $feature["August"];
}
... View more
10-08-2025
05:09 AM
|
2
|
1
|
642
|
|
POST
|
I've used your layers in a map and it works as expected. The code I'm using is var fs = FeatureSetByName($map, "Lawrence Zoning District", ["ZoningDistrict"]);
var WithinFS = Within($feature, fs);
iif(
Count(WithinFS) == 0,
"Not in a zoning district.",
First(WithinFS).ZoningDistrict
); which returns this when run in the text editor (using iif to return a message if there are no features returned by the Within) and this in the popup ("R-2", circled in red)
... View more
10-07-2025
01:57 PM
|
0
|
1
|
1121
|
|
POST
|
It doesn't matter if you have the layer within a group layer. This works on a test I set up. var fs = FeatureSetByName($map, "USA Census States")
var output = Within($feature,FS)
return {
type : 'text',
text : first(output).STATE_NAME
} Did you test the code on an actual feature in the Zoning District? Running the code in the editor will use the first feature in the FeatureSet, which may or may not give you a feature within the Zoning District layer. You can use a feature you know will work by filtering the parcel to a specific one. In my example, I can filter the earthquakes to a specific event to test it out. This code var feat = First(Filter($layer, "id = 'mb90114598'"))
var fs = FeatureSetByName($map, "USA Census States")
var output = Within(feat,FS)
return output
return {
type : 'text',
text : first(output).STATE_NAME
} returns this The code in your latest post fails because you're supplying an incorrect name for the FeatureSetByName function, which returns a null. When used in the WIthin function, it's being interpreted as a null feature in the Geometry Within function (which returns a boolean) instead of the FeatureSet Within function (which returns a FeatureSet)
... View more
10-06-2025
04:19 PM
|
0
|
5
|
1141
|
|
POST
|
What is the actual text in the $feature.Introduction?
... View more
10-06-2025
02:59 PM
|
0
|
1
|
1227
|
|
POST
|
You can see all the icons on the Calcite Design System's Icon page
... View more
10-01-2025
06:59 AM
|
0
|
1
|
513
|
|
POST
|
Lines 20 tests whether a relationship exists, not whether there are records in the relationship. The code fails when you try to access a field from a null in line 22 You'll have to test whether that relationship has any records. if (Count(related_site) > 0) {
... View more
09-30-2025
07:38 AM
|
1
|
0
|
708
|
|
POST
|
Chrome (140.0.7339.186) and Firefox (143.0.1) work, but Edge (140.0.3485.81) doesn't for me.
... View more
09-25-2025
08:09 AM
|
0
|
0
|
512
|
|
POST
|
Here's one way to calculate the difference (this shows the number of days since the beginning of the year). Note that the month number in the Date function is 0-based (0 is January) function StringToDate(input) {
var arrDate = Split(input, "/");
return Date(arrDate[2], arrDate[1] - 1, arrDate[0]);
}
var date1 = "01/01/2025";
var date2 = Text(Now(), "DD/MM/Y"); //gives today's date as dd/mm/yyyy
Floor(DateDiff(StringToDate(date2), StringToDate(date1), "days")); If your goal is to put this number into an indicator, then you have to return a FeatureSet containing that number function StringToDate(input) {
var arrDate = Split(input, "/");
return Date(arrDate[2], arrDate[1] - 1, arrDate[0]);
}
var date1 = "01/01/2025";
var date2 = Text(Now(), "DD/MM/Y"); //gives today's date as dd/mm/yyyy
var days = Floor(DateDiff(StringToDate(date2), StringToDate(date1), "days"));
return FeatureSet(
{
fields: [{ name: "Days", type: "esriFieldTypeInteger" }],
features: [{ attributes: { Days: days } }]
}
);
... View more
09-24-2025
01:00 PM
|
0
|
0
|
566
|
|
POST
|
First, check all the field names. I may have overlooked changing one back to your schema. Click the Run button in the Arcade editor to see if it's returning a FeatureSet. Add some Console messages to see what the code is doing a various intervals. This should help you figure out what's going wrong.
... View more
09-24-2025
07:55 AM
|
0
|
2
|
769
|
|
POST
|
It looks like it's selective. I still get the error.
... View more
09-23-2025
10:34 AM
|
0
|
0
|
1695
|
|
POST
|
That code should be var features = FeatureSetByName($map, 'Kartirane geoloske jedinice', ['PreferisanaStarost'], true);
Distinct(features, 'PreferisanaStarost');
... View more
09-23-2025
09:52 AM
|
0
|
0
|
548
|
|
POST
|
When posting code, please use the "Insert/edit code sample" button. It's easier to read and copy the code. A data expression must return a FeatureSet. Your code just returns an array of text strings. // Portal URL
var portalURL = "https://gis.(COMPANY_NAME).com/portal";
// Feature Layer ItemID
var layerItemID = "itemID";
// Layer index (usually 0)
var layerIndex = 0;
// Fields to include
var fields = ["T4PERMIT", "COMMODITY1", "OD", "Length_Miles"];
// Get FeatureSet from portal item
var fs = FeatureSetByPortalItem(
Portal(portalURL),
layerItemID,
layerIndex,
fields,
false
);
var grouped = GroupBy(
fs,
["T4PERMIT", "COMMODITY1", "OD"],
[{ name: "TotalMileage", expression: "Length_Miles", statistic: "SUM" }]
);
var finalResults = [];
for (var permit in Distinct(grouped, "T4PERMIT")) {
var permitVal = permit["T4PERMIT"];
var permitGroup = Filter(grouped, "T4PERMIT = @permitVal");
var textBlock = "<b>T4 Permit:</b> " + permitVal + "<br>";
for (var comm in Distinct(permitGroup, "COMMODITY1")) {
var commVal = comm["COMMODITY1"];
textBlock += " • <b>Commodity:</b> " + commVal + "<br>";
var commGroup = Filter(permitGroup, "COMMODITY1 = @commVal");
for (var row in commGroup) {
textBlock += "  ◦ <b>OD:</b> " +
row["OD"] +
" – <b>Mileage:</b> " +
Round(row["TotalMileage"], 2) +
"<br>";
}
}
Push(finalResults, { attributes: { Permits: textBlock } });
}
return FeatureSet(
{
fields: [{ name: "Permits", type: "esriFieldTypeString" }],
features: finalResults
}
); Using my test data, the code produces this list
... View more
09-23-2025
08:38 AM
|
1
|
5
|
1500
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a week ago | |
| 1 | a month ago | |
| 1 | a month ago | |
| 1 | 10-11-2023 06:18 AM | |
| 1 | 03-23-2026 09:23 AM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|