|
POST
|
You can use the $layer profile variable to get another record in your dataset with the Filter and First functions. The return uses a template literal. var sql
if (row < 3) {
sql = "ID = @row"
} else {
sql = "OBJECTID = @row"
}
var feat = First(Filter($layer, sql))
return `Secondary Contact ${feat.INSPECTOR_NAME} phone ${feat.PHONE}`;
... View more
03-20-2025
07:22 AM
|
1
|
2
|
1763
|
|
POST
|
It can be a integer since the value that's being inserted into the field is an integer (line 4)
... View more
03-18-2025
07:11 AM
|
0
|
0
|
2624
|
|
POST
|
Here's the script I came up with. It does your error checking, returning a table (InvalidTable function) with the error message if the featureset doesn't contain the fields or fields with domains. Since this could be a very memory-intensive code as it uses the Filter function for each combination of domains, I also include @jcarlson's Memorize function to read the FeatureSet into memory. Note that in my test, this used domains with a numeric code, so I used the description for its name (lines 111 and 121). If you use string codes, you can just use "key" and "ykey" instead of "xDomainMappings[key]" and "yDomainMappings[ykey]" in those lines. function InvalidTable(message) {
return FeatureSet(
{
fields: [{ alias: "error", name: "error", type: "esriFieldTypeString" }],
geometryType: "",
features: [{ attributes: { error: message } }]
}
);
}
function Memorize(fs) {
var temp_dict = {
fields: Schema(fs)["fields"],
geometryType: "",
features: []
};
for (var f in fs) {
var attrs = {};
for (var attr in f) {
attrs[attr] = Iif(TypeOf(f[attr]) == "Date", Number(f[attr]), f[attr]);
}
Push(temp_dict["features"], { attributes: attrs });
}
return FeatureSet(temp_dict);
}
// Define the field to extract coded domains from
var targetFields = ["xAxisField", "xAxisField"]; //Change this to match the actual field names
var targetXField = targetFields[0];
var targetYField = targetFields[1];
var inputFS = FeatureSetByPortalItem(
Portal("your portal"),
"itemId",
0,
targetFields
);
// Check if the feature set is empty
if (IsEmpty(inputFS)) {
return InvalidTable("Error: No features found in this dataset.");
}
// Get the schema for the layer to retrieve domain information
var fields = Schema(inputFS).fields;
var containsXTargetField = false;
var containsYTargetField = false;
var xDomainInfo;
var yDomainInfo;
// Loop through the schema fields to extract field names
for (var i = 0; i < Count(fields); i++) {
var field = fields[i];
if (field.name == targetXField) {
containsXTargetField = true;
// Retrieve the domain information for the XTarget field
if (field.domain != null) xDomainInfo = field.domain;
}
if (field.name == targetYField) {
containsYTargetField = true;
// Retrieve the domain information for the YTarget field
if (field.domain != null) yDomainInfo = field.domain;
}
}
// Check if the target field exists in the list of field names
// If the field does not exist, return an error
if (!containsXTargetField)
return InvalidTable(
`Error: Field '${targetXField}' not found in the feature set.`
);
if (!containsYTargetField)
return InvalidTable(
`Error: Field '${targetYField}' not found in the feature set.`
);
// If no domain is found, return a message
if (IsEmpty(xdomainInfo))
return InvalidTable(`Error: No domain found for field '${targetXField}'.`);
if (IsEmpty(ydomainInfo))
return InvalidTable(`Error: No domain found for field '${targetYField}'.`);
// Create a dictionary of domain mappings (assumes it's a coded value domain)
var xDomainMappings = {};
if (xDomainInfo.type != "codedValue")
return InvalidTable(
`Error: Domain for field '${targetXField}' is not coded-value.`
);
// If the domain type is coded value, we can extract the coded values and their descriptions
for (var i = 0; i < Count(xDomainInfo.codedValues); i++) {
var codedValue = xDomainInfo.codedValues[i];
xDomainMappings[`${codedValue.code}`] = codedValue.name;
}
var yDomainMappings = {};
if (yDomainInfo.type != "codedValue")
return InvalidTable(
`Error: Domain for field '${targetYField}' is not coded-value.`
);
// If the domain type is coded value, we can extract the coded values and their descriptions
for (var i = 0; i < Count(yDomainInfo.codedValues); i++) {
var codedValue = yDomainInfo.codedValues[i];
yDomainMappings[`${codedValue.code}`] = codedValue.name;
}
console(xDomainMappings)
//Create the fields to hold the counts
var fieldList = [{ alias: "Domain", name: "Domain", type: "esriFieldTypeString" }];
for (var key in xDomainMappings) {
Push(
fieldList,
{ alias: xDomainMappings[key], name: key, type: "esriFieldTypeInteger" }
);
}
//Store the fs in memory for multiple Filter calls
var fs = Memorize(inputFS);
//Loop through all the combinations of domains
var features = [];
for (var ykey in yDomainMappings) {
var attributes = { Domain: yDomainMappings[ykey] };
for (var xkey in xDomainMappings) {
var query = `${targetXField} = @xkey AND ${targetyField} = @ykey`;
attributes[xkey] = Count(Filter(fs, query));
//console(`ykey: ${ykey}, xkey: ${xkey}: ${attributes[xkey]}`);
}
Push(features, { attributes: attributes });
}
var dict = { fields: fieldList, features: features };
return FeatureSet(dict); I ran this on my data and got this table. I tested these results using this GroupBy function, return GroupBy(fs, targetFields, {name: "Count", expression: '1', statistic: 'Count'}) which gave me a table of the counts of each combination that was greater than zero.
... View more
03-17-2025
12:14 PM
|
0
|
0
|
1262
|
|
POST
|
There are a couple ways to simplify this script. You don't need to check if the values are greater than the previous values in the if statement (line 4-21) You don't need the Text function anywhere, since concatenating a string and a number will result in a string (lines 33 and 35) You also don't need the Text function to create a FeatureSet from a Dictionary (line 44). This was fixed as while ago, possibly in version 1.19 And you don't need the Alph array, since you can cast the variable i to a string also (lines 30 and 32). function GetPctColor(P) {
var Color = When(
P >= 0 && P < 5, "#d01111",
P < 10, "#cc2211",
P < 15, "#c83311",
P < 20, "#c34211",
P < 25, "#bf5112",
P < 30, "#bb5f12",
P < 35, "#b76c12",
P < 40, "#b37912",
P < 45, "#af8512",
P < 50, "#ab9012",
P < 55, "#a79a12",
P < 60, "#a2a312",
P < 65, "#919f12",
P < 70, "#819b12",
P < 75, "#719712",
P < 80, "#639312",
P < 85, "#558f11",
P < 90, "#478b11",
P < 95, "#3b8711",
"#2f8311"
);
return Color;
}
var fields = [];
var V = {};
for (var i = 5; i <= 95; i = i + 5) {
if (i % 5 == 0) {
var f = { name: `${i}`, type: "esriFieldTypeSmallInteger" };
Push(fields, f);
V[`${i}`] = i;
f = { name: "c" + i, type: "esriFieldTypeString", Length: 7 };
Push(fields, f);
V["c" + i] = GetPctColor(i);
}
}
var Ramp = {
fields: fields,
geometryType: "",
features: [{ attributes: V }]
};
return FeatureSet(Ramp);
... View more
03-17-2025
07:45 AM
|
1
|
1
|
2670
|
|
POST
|
How are you using this script? Running it as is returns a FeatureSet
... View more
03-17-2025
06:35 AM
|
0
|
3
|
2694
|
|
POST
|
To return the minimum date, you'll have to use FeatureSetByPortalItem to get the layer.
... View more
03-13-2025
12:51 PM
|
0
|
0
|
1323
|
|
POST
|
Can you give a better idea of what you'd like your final table to look like? Are you trying to get a summary of how many records are in the domains for each pair of fields? I'm guessing if your table looks like this id Field 1 Field2 1 domain 1 domain 1 2 domain 2 domain 1 3 domain 3 domain 3 4 domain 1 domain 1 5 domain 1 domain 2 you want your output table looking like this. Field 2, domain 1 Field 2, domain 2 Field 2, domain 3 Field 1, domain 1 2 0 0 Field 1, domain 2 1 1 0 Field 1, domain 3 0 0 1 Is this correct?
... View more
03-13-2025
12:04 PM
|
0
|
0
|
1308
|
|
POST
|
You shouldn't need the Text function in there either, unless you want use its formatting tools.
... View more
03-13-2025
08:25 AM
|
1
|
1
|
2556
|
|
POST
|
I ran a test for a double numeric field that has various values, including nulls. I didn't use the Number function when assigning the original attribute to the new feature (line 29) var jsonDictionary = {
fields: [
{ alias: "ID", name: "ID", type: "esriFieldTypeString" },
{ alias: "DoubleField", name: "DoubleField", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: [
{ attributes: { ID: 1, DoubleField: 6168.25 } },
{ attributes: { ID: null, DoubleField: 0 } },
{ attributes: { ID: 1, DoubleField: null } },
{ attributes: { ID: 2 } }
]
};
var fs = FeatureSet(jsonDictionary);
var out_dict = {
fields: [
{ name: "projectid", type: "esriFieldTypeString" },
{ name: "bestcost", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: []
};
for (var f in fs) {
Push(
out_dict["features"],
{ attributes: { projectid: Text(f["ID"]), bestcost: f["DoubleField"] } }
);
}
return FeatureSet(out_dict); This is the output table, with nulls remains as null in the double field.
... View more
03-13-2025
08:11 AM
|
1
|
3
|
2564
|
|
POST
|
Is there a reason you're trying to convert those values to a number? The Number function returns a 0 for a null value.
... View more
03-13-2025
07:22 AM
|
0
|
7
|
2574
|
|
POST
|
For the records where verifdat is populated, do you just want to keep that date? Give this a try When(
$record.size != null && $record.material != null && $record.verifdate == null, $record.survey_date,
$record.verifdate
);
... View more
03-12-2025
05:47 AM
|
1
|
0
|
1441
|
|
POST
|
You need the return, but when the if statement only has one line, you don't need brackets. This would work perfectly fine if ($record.size != null && $record.material != null && $record.verifdate == null) return $record.survey_date;
... View more
03-12-2025
05:39 AM
|
0
|
0
|
1443
|
|
POST
|
There's difference between the two. Week returns a value where the first week is 0 while ISOWeek returns a value where the first week is 1. Take a look at the difference using your example date (remember that month is zero-based)
... View more
03-11-2025
09:08 AM
|
0
|
0
|
479
|
|
POST
|
You can use the Arcade script ISOWeek($feature.surveydate) This is how it would look in the Field Calculator (with my data)
... View more
03-11-2025
08:00 AM
|
4
|
2
|
2702
|
|
BLOG
|
That link points to the Instant Apps sessions blog article. It should be https://www.esri.com/arcgis-blog/products/experience-builder/announcements/arcgis-experience-builder-at-the-2025-devtech-summit/
... View more
03-11-2025
07:17 AM
|
1
|
0
|
308
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-04-2025 06:39 AM | |
| 1 | 05-01-2026 08:26 AM | |
| 1 | 04-10-2026 12:01 PM | |
| 1 | 04-13-2026 09:11 AM | |
| 1 | 10-11-2023 06:18 AM |
| Online Status |
Offline
|
| Date Last Visited |
3 weeks ago
|