It returns an empty feature set. I created another script that returns an empty feature set and that one indeed works fine (thanks, @jcarlson!). It might be something in the script (or data, or most likely portal). Here it is:
// declaring portal variable
var portal = Portal("https://myportal.com/portal");
// filter work order feature set for required fields
var fs = Filter(
FeatureSetByPortalItem(
portal,
'3f959g85g959595954ff9ggkdkgr',
0,
["OBJECTID", "EQUIPMENT", "STATUS", "DATE_CREATED"],
false,
),
"STATUS LIKE 'Not Performed' AND PM_CODE LIKE 'SG-100SW-3'"
)
//generating an array of equipment values that have consecutive Not Performed cycles
var pairs = []
for (var r in fs) {
var keys = r["EQUIPMENT"];
var values = r["DATE_CREATED"];
var keyvalue = {"key": keys, "value": values}
Push(pairs, keyvalue)
}
var resultArray = [];
for (var i = 0; i < Count(pairs)-1; i++) {
var current = pairs[i];
var next = pairs[i + 1];
if (Equals(current.key, next.key) && Abs(DateDiff(Date(current.value),Date(next.value), "days")) <= 93) {
Push(resultArray, current.key);
}
}
//adding single quotes to the strings in the array so that the SQL filter recognizes them in order to match them to the equipment layer
var newFilter = [];
for (var i = 0; i< Count(resultArray)-1; i++) {
var string = "'" + resultArray[i] + "'";
newFilter[i] = string
}
var eqFilter = `EQUIPMENT IN (${Concatenate(newFilter, ',')})`
//filtering the equipment layer for the equipment values in the array
return Filter(FeatureSetByPortalItem(
portal,
'otmbd4968695gmb09fkv99vkvv',
0,
['*'],
false,
),
eqFilter)
This script works perfectly for two other PM codes, with 31, respectively 62 days.