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
Solved! Go to Solution.
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: [] } }]
Thanks Mr. thejus kambi, when apply your idea i have a small problem.
, in linkedQuery
when ids is null or empty there is no results appear in the grid
i tried to solve it when click on grid record pass fk_pk to linkedQuery
but fails.
how i can search using related table and return the results on the grid, and when click in any records in grid refer to the map.
The ids in linkedQuery are supposed to be empty while configuration and should be populated automatically. After looking into the implementation, I found there is an undocumented property required for this to work. You need to add linkField with fk field.
linkField: "fk field",
linkedQuery: {
url: "<LayerA url>",
type: "spatial", //you could probably use more of the queryParameters options like outfields etc
idProperty: "pk field",
ids: []
}
Thank you for your replaying, i'm tracing the code and note that it need to add
,linkedID but when run my app the print in console where clause note it empty
console.log ==== results
pk_num in ()
.
where in clause is empty
.I will try to add linkedIDS in search queryParameters
It would be helpful, if you could share something, I have been replying with lot of assumptions, and I will not be able to confirm if something is wrong or correct.
.Hello thejus kambi, all things is right
But the results of grid show the Layer A fields not table B. How we can show the fields of table B in the grid and when users click on the record zoom to it.Here's the sample:
define([
'dojo/on',
'dojo/topic'
], function (on, topic) {
return {
map: true,
mapClickMode: true,
layers: [
{
//*********************************
name: 'LayerA&TableB',
queryParameters:{
type:'table',
url: 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...',
outFields: ['*']
},
linkField: 'sf_311_serviceoid',
idProperty: 'objectid'
,
attributeSearches:[{
name: 'Search for TableB fields',
searchFields: [
{
//**************
name: 'Inspector Name',
label: 'Inspector Name',
expression: ' ( 1 = 1 )', // ( sf_311_serviceoid = \'[value]\' )
placeholder: 'Enter the Inspector Name',
required: true,
minChars: 1
}
]
, title: 'Inspector',
topicID: 'InspectorQuery',
gridOptions: {
columns: [
{
field: 'sf_311_serviceoid',
label: 'Name',
width: 150
},
{
field: 'agree_with_incident',
label: 'agree_with_incident',
width: 150
}
],
sort: [
{
attribute: 'sf_311_serviceoid',
descending: 'ASC'
}
]
}
}]
,
linkedQuery: {
url: 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...',
type: 'spatial', //you could probably use more of the queryParameters options like outfields etc
linkField: 'objectid',
outFields: ['*'],
ids: []
}
//*********************************
}
]
};
});
The results:
Unfortunately, the framework does not support that.You would have to modify the widget for that. Another option would be to create a service with both the table and Featurelayer joined.
Hi every one, I was return the results of table on grid and need when click record make a new query and zoom to .
related point in the map, My codes below but i have a problem in centerAndzoom is undefined
define([
'dojo/on',
'dojo/topic',
'esri/map',
'esri/tasks/query',
'esri/tasks/QueryTask',
'esri/geometry/Extent',
'esri/geometry/Point',
'esri/SpatialReference'
], function (on, topic, map, Query, QueryTask,Extent,Point,SpatialReference) {
//*****************
var queryTask, query;
function showResults(results) {
//This function is run when the query has finished.
//It zooms the map to the extent of the first feature returned by the query.
var result = results.features[0];
if (result.geometry.type == 'point' ){
var pointx;
var pointy;
pointx = results.features[0].geometry.x;
pointy = results.features[0].geometry.y;
point = new esri.geometry.Point(pointx, pointy,new SpatialReference({wkid:4326}));
alert(pointx );
this.map.centerAndZoom(point,15);
}
}
function errResults(err) {
//This section runs if there's a problem with the query
alert("Sorry, there's a problem with the query : " + err);
}
//*****************
return {
map: true,
mapClickMode: true,
spatialReference: null,
layers: [
{
//*********************************
name: 'LayerA&TableB',
queryParameters:{
type:'table',
url: 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...',
outFields: ['*']
},
// linkField: 'sf_311_serviceoid',
// idProperty: 'objectid'
// ,
attributeSearches:[{
name: 'Search for TableB fields',
searchFields: [
{
//**************
name: 'Inspector Name',
label: 'Inspector Name',
expression: ' ( 1 = 1 )', // ( sf_311_serviceoid = \'[value]\' )
placeholder: 'Enter the Inspector Name',
required: true,
minChars: 1
}
]
, title: 'Inspector',
topicID: 'InspectorQuery',
gridOptions: {
columns: [
{
field: 'sf_311_serviceoid',
label: 'Name',
width: 150,
renderCell: function (object, value, node) {
on(node, 'click', function () {
queryTask = new QueryTask('https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...
query = new Query();
query.returnGeometry = true;
query.outFields = ["*"];
query.where = '1 = 1';
queryTask.execute(query,showResults,errResults)
});
node.innerHTML = '<i class=\'fa fa-pencil\' style=\'margin-left:8px;\'></i>';
}
},
{
field: 'agree_with_incident',
label: 'agree_with_incident',
width: 150
}
],
sort: [
{
attribute: 'sf_311_serviceoid',
descending: 'ASC'
}
]
}
}]
/*,
linkedQuery: {
url: 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/...',
type: 'spatial', //you could probably use more of the queryParameters options like outfields etc
linkField: 'objectid',
outFields: ['*'],
ids: []
}
*/
//*********************************
}
]
};
});
up