I am modifying the sample code from: https://developers.arcgis.com/javascript/jssamples/fl_query_related.html and I don't understand how to configure the section:
function findRelatedRecords(evt) {
var features = evt.features;
var relatedTopsQuery = new RelationshipQuery();
relatedTopsQuery.outFields = ["*"];
relatedTopsQuery.relationshipId = 0;
relatedTopsQuery.objectIds = [features[0].attributes.BUILDING_PK];
buildingFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
console.log("related recs: ", relatedRecords);
if ( ! relatedRecords.hasOwnProperty(features[0].attributes.BUILDING_PK) ) {
console.log("No related records for Building: ", features[0].attributes.BUILDING_PK);
return;
}
var fset = relatedRecords[features[0].attributes.BUILDING_PK];
var items = array.map(fset.features, function(feature) {
return feature.attributes;
});
//Create data object to be used in store
var data = {
identifier: "BUILDING_PK", //This field needs to have unique values
label: "Building", //Name field for display. Not pertinent to a grid but may be used elsewhere.
items: items
};
//Create data store and bind to grid.
store = new ItemFileReadStore({ data:data });
grid.setStore(store);
grid.setQuery({ BUILDING_PK: "*" });
});
}
How do I indicate the related fields?
The service is restricted access and requires authentication.
The relationships for this layer are as follows:
Relationships:
Thanks
Gwynn
Solved! Go to Solution.
Gwynn,
How do I indicate the related fields?
this line states that all the relates fields should be returned:
relatedTopsQuery.outFields = ["*"];
This line here is testing if there are any relates with that ObjectId
if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
This line is specifying the relate id number:
relatedTopsQuery.relationshipId = 0;
so for your layer this would mean the tbl_BuildingStatus
This line that you have changed is incorrect. A relate query need to know which feature (by ObjectId) that you are wanting the related record(s) for:
relatedTopsQuery.objectIds = [features[0].attributes.BUILDING_PK];
it should revert back to:relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
Gwynn,
How do I indicate the related fields?
this line states that all the relates fields should be returned:
relatedTopsQuery.outFields = ["*"];
This line here is testing if there are any relates with that ObjectId
if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
This line is specifying the relate id number:
relatedTopsQuery.relationshipId = 0;
so for your layer this would mean the tbl_BuildingStatus
This line that you have changed is incorrect. A relate query need to know which feature (by ObjectId) that you are wanting the related record(s) for:
relatedTopsQuery.objectIds = [features[0].attributes.BUILDING_PK];
it should revert back to:relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
OK I changed it to the following and now my map layer will not display. What have I got wrong?
function findRelatedRecords(evt) {
var features = evt.features;
var relatedTopsQuery = new RelationshipQuery();
relatedTopsQuery.outFields = ["*"];
relatedTopsQuery.relationshipId = 0;
relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
buildingFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
console.log("related recs: ", relatedRecords);
if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
console.log("No related records for Building: ", features[0].attributes.OBJECTID);
return;
}
var fset = relatedRecords[features[0].attributes.OBJECTID];
var items = array.map(fset.features, function(feature) {
return feature.attributes;
});
//Create data object to be used in store
var data = {
identifier: "OBJECTID", //This field needs to have unique values
label: "Building", //Name field for display. Not pertinent to a grid but may be used elsewhere.
items: items
};
//Create data store and bind to grid.
store = new ItemFileReadStore({ data:data });
grid.setStore(store);
grid.setQuery({ OBJECTID: "*" });
});
}
Thanks
Gwynn,
what do you mean
and now my map layer will not display
Changing this code should not have anything to do with your layer displaying in the map.
You are correct. The authentication was not being triggered.
Now it works!!!
Thanks.