I'm not sure if i'm overlooking things or this is not yet supported, but i'm curious if the default JavaScript API (v4) popup supports related records.
I have the following situation:
Example in default JSAPI popup:
Example in Webappbuilder:
What i'm looking for is the option to add the functionality regarding the related records in the second screenshot to the situation in the first screenshot.
My question is twofold:
Q1. No this is not supported by default.
Q2. You will need to use QueryTask executeRelationshipQuery
Once you get the featureSet results from the Query you will loop through the results and generate html markup to append to the popup widgets content properly. This is not going to be a simple one of two lines of code type customization.
Thanks for the response!
Too bad this functionality isn't default (this seems to be the case in the vanilla options within for example webappbuilder).
- - Some context:
I have played around with speaking to the queryRelated REST endpoint directly via hitTest, getting all related records and appending them to a custom popup (with html markup). With this there were two issues:
- Buggy peformance when hitting multiple features
- Identity manager didnt seem to cover the authentication when getting the attachmentURL(of the related record) and displaying it
-- End of context
With the suggested idea of using QueryTask. In order to perform a QueryTask one would need an OBJECTID for the current selected feature (correct me if i'm wrong). Is there any other way to do this other than using hitTest?
WAB is a Highly customized app built on top of JS API (so not vanilla at all). You can borrow code from WAB if you want the file you are looking for is the jimu/RelatedRecordsPopupProjector.js
You can use the popup widgets selectedFeature property and then get the OID from the returned value.
Vanilla might have been the wrong term there. The complexity of the sourcefile you linked is way beyond my understanding
The selectedFeature property looks like the thing I need. I was able to implement it partly. I'm now getting an object returned as the selectedFeature after an on-click action.
Two things:
- To get the current selected feature I would need some kind of event listener. view.on("click", function(event) doesn't seem like the right one.
- Trying to access the OBJECTID via view.popup.selectedFeature.attributes.OBJCTID gives me an error (also via data.getAttributes("OBJECTID")). How would one access this object?
Is ObjectID part of the attributes in you console above?
Yes, see screenshot (erased some values in paint due to privacyreasons).
view.popup.selectedFeature.attributes also gives an error
G,
Sounds like a timing issue. The selected feature is undefined at the time when you attempt to get the attributes property. So you need to use WatchUtils to watch the popups selectedFeature property for being defined before you attempt to access the attributes property:
https://developers.arcgis.com/javascript/latest/api-reference/esri-core-watchUtils.html#whenDefined
This still gives strange results. Sometimes, when clicking one feature, I get a burst of console logs (some of which are null, often one more than the previous burst). Also view.popup.attributes still doesnt work. Feels indeed like a timing thing, as all the logs happen before the popup draws.
G,
There is not need to have the watch occur inside a view click event. Just add this after you create your view:
watchUtils.when(view.popup, "selectedFeature", function(evt){
console.info(view.popup.selectedFeature.attributes);
});