I haven't been able to find any examples of this or anything similar but I am wondering if it is possible to push query results to a feature form. What I need to have happen is when someone selects a species from a dropdown within the feature form it will populate 3 fields with information that is queried from a table (Genus, Species and USDA Plant Code). I have the query working and it returns the fields in the console but I don't quite know how to take those results and populate the feature form. Below is what I have now... also, I see that the "value-change" event for the feature form can be set on a specific field but there is no example of how that should look? In reality, I would only like this to occur when the "COMMON" field dropdown is modified.
I am using this example (https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/)
Code Updated (6/10/22)
What I have below is currently not working.
// Highlights the clicked feature and display
// the feature form with the incident's attributes.
function selectFeature(objectId) {
// query feature from the server
obsLayer.queryFeatures({
objectIds: [objectId],
outFields: ["*"],
returnGeometry: true
}).then((results) => {
if (results.features.length > 0) {
editFeature = results.features[0];
// display the attributes of selected feature in the form
featureForm.feature = editFeature;
console.log("populate form");
//**testing**
//this query is performed when the selection changes on anything.
//Returns the correct information
featureForm.on("value-change", () => {
var featureAtt = featureForm.getValues();
var attributesSpecies = Object.entries(featureAtt).map(([key, value]) => ({key,value}));
var speciesID = attributesSpecies[9].value;
var speciesQuery = speciesTable.createQuery();
//speciesQuery.objectIds = [objectId];
speciesQuery.outfields = ["*"];
speciesQuery.returnGeometry = false;
speciesQuery.returnDistinctValues = true;
speciesQuery.where = "ID = " + speciesID + "";
//console.log(speciesQuery);
speciesTable.queryFeatures(speciesQuery).then(function(results){
var attributeArray = new Array();
results.features.forEach(function(item) {
attributeArray.push(item.attributes);
});
//console.log(attributeArray[0].GENUS);
var attr = [];
attr["GENUS"] = attributeArray[0].GENUS;
attr["SPECIES"] = attributeArray[0].SPECIES;
attr["PLANTCODE"] = attributeArray[0].PCODE;
console.log(attr);
editFeature.attributes.GENUS = attributeArray[0].GENUS,
editFeature.attributes.SPECIES = attributeArray[0].SPECIES,
editFeature.attributes.PLANTCODE = attributeArray[0].PCODE
})
});
//**end testing**
// highlight the feature on the view
view.whenLayerView(editFeature.layer).then((layerView) => {
highlight = layerView.highlight(editFeature);
});
}
console.log(editFeature);
});
}