I'm looking at creating a new field in a returned feature set in ArcGIS Dashboard. I have the arcade code which is successfully returning a combined feature set from two datasets, however, I would like the count of rows from registry so that I can run some advanced formatting code in the table where the type is Features.
Essentially I want to return "Batch_Number"|"Count_of_Batch_Number_from_Registry"|etc
Solved! Go to Solution.
You can insert calculated values into new fields easily. I've just added lines 16, 23, 44, and 56. You also don't need all the null assignment in the registry loop. If they're not assigned, they will be set to null automatically.
// Set portal
var portal = Portal("https://arcgis.com/");
// Create featureset from registry (include all fields)
var unfilteredregistry = FeatureSetByPortalItem(portal, '', , ['*'], false);
// Filter registry to only include rows where "Batch_Number" is not null
var registry = Filter(unfilteredregistry, "Batch_Number IS NOT NULL");
// Create featureset from batch submission (include all fields)
var batchsubmission = FeatureSetByPortalItem(portal, '', 0, ['*'], false);
// Initialise empty feature array
var features = [];
var feat;
var batchCount = count(registry);
// Iterate through batch submission
for (var b in batchsubmission) {
feat = {
attributes: {
OBJECTID: b["objectid"],
Batch_Number: b["batch_number"], // <- map lowercase field to consistent name
Batch_Count: batchCount,
Batch_Submission_Date: b["date_of_batch_submission_for_si"],
Site_Assessment_Complete: b["date_of_site_assessment_complet"],
Batch_Review_Priority: b["BatchReviewPriority"],
Registry_Acquisition_St: b["RegistryAcquisitionStart"],
Registry_Acquisition_Co: b["RegistryAcquisitionComplete"],
Batch_Acquirer: b["BatchAcquirer"],
Elapsed_Time: b["RegistryAcquisitionElapsedTim"],
Registry_Acquisition_Status: b["Registry_Acquisition_Status"],
Site_Assessment_Status: b["Site_Assessment_Status"]
}
};
Push(features, feat);
}
// Iterate through registry
for (var r in registry) {
feat = {
attributes: {
OBJECTID: r["OBJECTID"],
Batch_Number: r["Batch_Number"],
Batch_Count: batchCount
}
};
Push(features, feat);
}
// Create structured dictionary for Featureset
var combinedDict = {
fields: [
{ name: "OBJECTID", type: "esriFieldTypeObjectID"},
{ name: "Batch_Number", type: "esriFieldTypeString" },
{ name: "Batch_Count", type: "esriFieldTypeInteger" },
{ name: "Batch_Submission_Date", type: "esriFieldTypeDate" },
{ name: "Site_Assessment_Complete_Date", type: "esriFieldTypeDate" },
{ name: "Batch_Review_Priority", type: "esriFieldTypeString" },
{ name: "Registry_Acquisition_Start", type: "esriFieldTypeDate" },
{ name: "Registry_Acquisition_Complete", type: "esriFieldTypeDate" },
{ name: "Batch_Acquirer", type: "esriFieldTypeString" },
{ name: "Elapsed_Time", type: "esriFieldTypeInteger" },
{ name: "Registry_Acquisition_Status", type: "esriFieldTypeString" },
{ name: "Site_Assessment_Status", type: "esriFieldTypeString" }
],
geometryType: "",
features: features
};
// Return combined feature set
return FeatureSet(combinedDict);
You can insert calculated values into new fields easily. I've just added lines 16, 23, 44, and 56. You also don't need all the null assignment in the registry loop. If they're not assigned, they will be set to null automatically.
// Set portal
var portal = Portal("https://arcgis.com/");
// Create featureset from registry (include all fields)
var unfilteredregistry = FeatureSetByPortalItem(portal, '', , ['*'], false);
// Filter registry to only include rows where "Batch_Number" is not null
var registry = Filter(unfilteredregistry, "Batch_Number IS NOT NULL");
// Create featureset from batch submission (include all fields)
var batchsubmission = FeatureSetByPortalItem(portal, '', 0, ['*'], false);
// Initialise empty feature array
var features = [];
var feat;
var batchCount = count(registry);
// Iterate through batch submission
for (var b in batchsubmission) {
feat = {
attributes: {
OBJECTID: b["objectid"],
Batch_Number: b["batch_number"], // <- map lowercase field to consistent name
Batch_Count: batchCount,
Batch_Submission_Date: b["date_of_batch_submission_for_si"],
Site_Assessment_Complete: b["date_of_site_assessment_complet"],
Batch_Review_Priority: b["BatchReviewPriority"],
Registry_Acquisition_St: b["RegistryAcquisitionStart"],
Registry_Acquisition_Co: b["RegistryAcquisitionComplete"],
Batch_Acquirer: b["BatchAcquirer"],
Elapsed_Time: b["RegistryAcquisitionElapsedTim"],
Registry_Acquisition_Status: b["Registry_Acquisition_Status"],
Site_Assessment_Status: b["Site_Assessment_Status"]
}
};
Push(features, feat);
}
// Iterate through registry
for (var r in registry) {
feat = {
attributes: {
OBJECTID: r["OBJECTID"],
Batch_Number: r["Batch_Number"],
Batch_Count: batchCount
}
};
Push(features, feat);
}
// Create structured dictionary for Featureset
var combinedDict = {
fields: [
{ name: "OBJECTID", type: "esriFieldTypeObjectID"},
{ name: "Batch_Number", type: "esriFieldTypeString" },
{ name: "Batch_Count", type: "esriFieldTypeInteger" },
{ name: "Batch_Submission_Date", type: "esriFieldTypeDate" },
{ name: "Site_Assessment_Complete_Date", type: "esriFieldTypeDate" },
{ name: "Batch_Review_Priority", type: "esriFieldTypeString" },
{ name: "Registry_Acquisition_Start", type: "esriFieldTypeDate" },
{ name: "Registry_Acquisition_Complete", type: "esriFieldTypeDate" },
{ name: "Batch_Acquirer", type: "esriFieldTypeString" },
{ name: "Elapsed_Time", type: "esriFieldTypeInteger" },
{ name: "Registry_Acquisition_Status", type: "esriFieldTypeString" },
{ name: "Site_Assessment_Status", type: "esriFieldTypeString" }
],
geometryType: "",
features: features
};
// Return combined feature set
return FeatureSet(combinedDict);
Thank you Ken, however, the count for registry when in a table has counted the entire number of rows in registry, and hasn't groupedby each corresponding batch number.
Is this still possible? Very much appreciate your response on this
I've realised it's probably not possible. To have in table form would be to have a list with a table in it, which has worked well