Select to view content in your preferred language

Include count field in combined ArcGIS dashboard code

161
3
Jump to solution
3 weeks ago
Labels (2)
PDouglassEPD
Emerging Contributor

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

 

// 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;


// 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_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_Submission_Date: null,
      Site_Assessment_Complete: null,
      Batch_Review_Priority: null,
      Registry_Acquisition_St: null,
      Registry_Acquisition_Co: null,
      Batch_Acquirer: null,
      Elapsed_Time: null,
      Registry_Acquisition_Status: null,
      Site_Assessment_Status: null
    }
  };
  Push(features, feat);
}


// Create structured dictionary for Featureset
var combinedDict = {
  fields: [
    { name: "OBJECTID", type: "esriFieldTypeObjectID"},
    { name: "Batch_Number", type: "esriFieldTypeString" },
    { 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);
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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);

 

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

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);

 

PDouglassEPD
Emerging Contributor

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

0 Kudos
PDouglassEPD
Emerging Contributor

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

0 Kudos