Query with related records in cmv map viewer tamplate

3866
19
Jump to solution
08-09-2016 09:34 AM
OracleEsri
New Contributor

Hi every one, I'm working in cmv map viewer, i have layer with related records, so i need to query using related data, how i can do that ?

layer A related to table B using pk--> fk

Query will done in table B and results appear in grid afterthat when click on record zoom to it.

thanks for all

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

Think like, you are queying tableB with a relation/linkedQuery to LayerA. and not the other way around. Without you sharing you configuration, I cannot confirm but,your configuration should look something like below

//only the layers section
layers: [{
    name: "LayerA&TableB",
    .
    .
    queryParamerters:{
          type:"table",
          url: "<tableB url>",
          .
          .
    },
    attributeSearches:[{
          name: "Search for TableB fields",
          searchFields: [{tableBField options}],
          gridOptions: {
              columns: [],
              sort: []
          }
    }],
    linkedQuery: {
          url: "<LayerA url>",
          type: "spatial",      //you could probably use more of the queryParameters options like outfields etc
          idProperty: "pk field",
          ids: []
    }
}]

View solution in original post

0 Kudos
19 Replies
thejuskambi
Occasional Contributor III

How are you displaying the table? Are you using the user contributed widget "AttributeTable" or "Search widget" ?

0 Kudos
OracleEsri
New Contributor

Using Search widget

0 Kudos
thejuskambi
Occasional Contributor III

You can use the linkedQuery option to do that. This option is part of AttributeTable. But you can add it to the search layer or attributeSearches properties depending on your configurations for the search. If you add it to layer, it will apply for all attributeSearches, or you can have different one for each attributeSearches. so your configuration should have something like below.

the layer will contain the table B details and the linkedQuery will contain layer A details. I hope the pk and fk are same names.

                    linkedQuery: {

                        url: layer A url,

                        idProperty: fk,

                        ids: [] // if linkedQuery, then store the linkedIDs for use in linked query

                    },

Hope this works out.

OracleEsri
New Contributor

Thank you for your replay, do you mean used this widget

cmv-widgets/README.md at master · tmcgee/cmv-widgets · GitHub

in my application?

0 Kudos
thejuskambi
Occasional Contributor III

In a way yes, the Search Widget in the below link already uses the "Attribute Table" widget (its a dependency for Search Widget).

cmv-widgets/widgets/Search at master · tmcgee/cmv-widgets · GitHub

OracleEsri
New Contributor

Thank you for replaying, can give me complete example to apply it

0 Kudos
thejuskambi
Occasional Contributor III

I don't have the set or the layer table relation. If you attach you config file with search configuration, updated to best of you knowledge. I could look and fix/add the linkQuery for you. Or @Tim McGee​ can help you.

0 Kudos
OracleEsri
New Contributor

Ok, i need to ask how I can search in fields from table (B) not in Layer (A).

Thanks

0 Kudos
OracleEsri
New Contributor

Up

0 Kudos