Related table field in a popupTemplate function?

1699
10
02-14-2019 06:40 AM
JayHill
Occasional Contributor II

I cannot figure out how to call the related field using this function to populate the content of the popup. I have tried relationships/0/FieldName everywhere I thought it was necessary with no luck. I think I need to call fieldInfos within the content syntax, Correct?

            liquefactionPopup = function(value, key, data) {
                var content = "";

                if (key === "LQSHazardUnit") {
                    if (data.LQSHazardUnit) { 
                        content += "<span class='bold' title='Magnitude'><b>LQSHazardUnit: </b></span>" + data.LQSHazardUnit + "<br/>";
                    }
                }
                if (key === "LQSMappedScale") {
                    if (data.LQSMappedScale) { 
                        content += "<span class='bold' title='Longitude'><b>LQSMappedScale: </b></span>" + data.LQSMappedScale + "<br/>";
                    }
                }
}
                return content;
            }


            const liquefaction = new FeatureLayer({
                url: "https://services.arcgis.com/3",
                title: "Liquefaction Susceptibility",
                visible: false,
                outFields: ["*"],
                popupTemplate: {
                    title: "Liquefaction Susceptibility",
                    content: "{LQSHazardUnit:liquefactionPopup}{LQSMappedScale:liquefactionPopup}"
                },
            });
0 Kudos
10 Replies
BirajaNayak
Esri Contributor

Hi Jay,

Yes, please include fieldinfos in popupTemplate.

You can go through the below sample "Create and use a popup template that references fields from a relationship" which may provide some help:

Popup with related fields | ArcGIS API for JavaScript 3.27 

Thanks,

Biraja

0 Kudos
JayHill
Occasional Contributor II

Biraja

Thanks for the reply! I forgot to mention I'm using 4.10. Also since I am using a function populate the content of the popupTemplate, are fieldInfos necessary?

0 Kudos
irtizahussain
Occasional Contributor

I was also looking for this but i think there is no solution available for this in 4.x yet, So i switched to 3.x and i found this.

Have a look ,it might be helpful for you.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Then this is the 4.x sample that shows you how t use relate fields in a popup:

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=popup-multiple... 

BirajaNayak
Esri Contributor

Hi Jay,

I have not used function for populating content. I can work on it and get back to you. As you have seen in the example both 3.x and 4.x , fieldinfos works for related table fields.

Thanks,

Biraja

0 Kudos
JayHill
Occasional Contributor II

Robert and Biraja

I've been trying to use both related fields and attachments within my popupTemplate function following some of the syntax in that example. Nothing is working for me. Should I abandoned the popupTemplate function altogether and just use fieldInfos? Or am I missing how to use fieldInfos along with the function?  I would really like to keep the function though for it checks for nulls and does some other custom html styling.

0 Kudos
BirajaNayak
Esri Contributor

Hi Jay,

I tried to pass content using function ( Tested with my colleague Jose Banuelos)  but can not read the values for related tables. You can log a case with Esri Support to look into more.

The below 4x sample using fieldinfos for related tables and attachment:

ArcGIS API for JavaScript Sandbox 

Again, if you find issues after using above sample, then you can contact Esri Support Services to diagnose the issue more.

Thanks,

Biraja 

0 Kudos
JayHill
Occasional Contributor II

Biraja

Thanks

I have it working now by not passing the related data through the function. I call the function on the unrelated data in the text area of popupTemplate. See below.

                popupTemplate: {
                     title: "<b>{relationships/0/HazardName}</b>",
                     content: [{
                         type: "fields",
                         fieldInfos: [{
                            fieldName: "relationships/0/Description",
                            visible: false,
                            label: "Hazard Description"
                        }, {
                         fieldName: "relationships/0/HazardName",
                         visible: false,
                         label: "Hazard"
                        }]
                     },
                     {
                    type: "text",
                    text: "<b>Description: </b>{relationships/0/Description}<br>{LQSMappedScale:liquefactionPopup}"
                }]
                     }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
BirajaNayak
Esri Contributor

Hi Jay,

That is what I observed during my testing. That is why I asked to contact Esri Support Services to work on it further or may be an enhancement for this behavior.

Thanks,

Biraja