javascript API 4.6 - IdentifyTask - get attributes names instead of attributes alias in result

619
7
02-08-2018 11:25 AM
MaximeDemers
Occasional Contributor III

I wonder if it's possible to parameter the IdentifyTask in order that the result features attributes would be using the fields names instead of the fields alias.

This is because fields names are less likely to be changed than alias over the course of time.

Also, I dont how the API would handle fields that have the same alias. That could happen...

Thank you!

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Maxime,

   No the ArcGIS Server Identify Task has always returned field aliases. It would be something that would have to change at the ArcGIS Server level and would be very unlikely to happen.

0 Kudos
MaximeDemers
Occasional Contributor III

I notice the javacript API v3.23 is not using the same type of REST service for IdentifyTask than the v4.X API

In v3.23 its a query that is made and the result contains a mapping between fieldNames and aliases and the returned feature's (graphic) attributes use fieldNames

https://mydomain.com/arcgis/rest/services/DEV/MY_MAP_SERVICE/MapServer/2/query?f=json&where=CD_POSTL... 

In v4.x its an identify and the result does not contains the mapping between fieldNames and aliases and returned feature's (graphic) attributes use aliases

https://mydomain.com/arcgis/rest/services/DEV/MY_MAP_SERVICE/MapServer/identify?f=json&tolerance=15&... 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Maxime,

   Maybe you should explain what you are doing in more detail then. I thought this question was about the IdentifyTask. When using the IdentifyTask an identify operation on the rest services is done not a query.

Right from the IdentifyTask 3.23 Docs:

Performs an identify operation on the layers of a map service resource exposed by the ArcGIS Server REST API.
0 Kudos
MaximeDemers
Occasional Contributor III

Ok yes!

In v3.23 you don't have to create a new IdentifyTask when using mapService, you just have to define the infoTemplates parameter of the ArcGISDynamicMapServiceLayer object and the API handles the request automatically, and it uses a query not an identify.

ArcGISDynamicMapServiceLayer | API Reference | ArcGIS API for JavaScript 3.23 

I will do the same in v4.6, I will use QueryTask instead of IdentifyTask, I think that will solve my problem.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Maxime,

   OK that explains it. If you had mentioned that you were using the maps popup then that would have been better. I thought you were specifically talking about the IdentifyTask as in your threads title.

0 Kudos
MaximeDemers
Occasional Contributor III

Ok sorry about that Robert, I am not super familiar with the javascript API.

Thank you for your help anyway, it was really appreciated.

Have a good day!

0 Kudos
marko_antoniopachas_tavara
New Contributor

Hi Maxime Demers, I have the same problem with mi Identify Tool and I solved it doing this:

(Has API JavaScript 3.12, and works with AGS 10.5, you have to keep in mid that in previous versión of AGS, can't call original name of attributes)

I'll put some aditional lines, on IdentifyParams, do that:

var identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = this._tolerance;
identifyParams.height = this.map.height;
identifyParams.width = this.map.width;
identifyParams.returnGeometry = true;
identifyParams.returnFieldName = true;

And this is the API JS with added text in bold from API Javascript called IdentifyParameters.js located in your API location.

// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.12/esri/copyright.txt for details.
//>>built
define("esri/tasks/IdentifyParameters", "dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/json dojo/has ../kernel ../layerUtils ../geometry/jsonUtils ../geometry/scaleUtils".split(" "), function (g, e, h, f, n, p, k, q, r) {
var d = g(null, {
declaredClass: "esri.tasks.IdentifyParameters",
constructor: function () {
this.layerOption = d.LAYER_OPTION_TOP
},
geometry: null,
spatialReference: null,
layerIds: null,
tolerance: null,
returnGeometry: !1,
returnFieldName: !1,
mapExtent: null,
width: 400,
height: 400,
dpi: 96,
layerDefinitions: null,
timeExtent: null,
layerTimeOptions: null,
dynamicLayerInfos: null,
toJson: function (b) {
var c = b && b.geometry || this.geometry,
a = this.mapExtent,
d = this.spatialReference,
e = this.layerIds;
b = {
tolerance: this.tolerance,
returnGeometry: this.returnGeometry,
returnFieldName:this.returnFieldName,
imageDisplay: this.width + "," + this.height + "," + this.dpi,
maxAllowableOffset: this.maxAllowableOffset
};
if (c) {
var l = c.toJson();
delete l.spatialReference;
b.geometry = f.toJson(l);
b.geometryType = q.getJsonType(c)
}
d ? b.sr = d.wkid || f.toJson(d.toJson()) : c && c.spatialReference ? b.sr = c.spatialReference.wkid ||
f.toJson(c.spatialReference.toJson()) : a && a.spatialReference && (b.sr = a.spatialReference.wkid || f.toJson(a.spatialReference.toJson()));
a && (b.mapExtent = a.xmin + "," + a.ymin + "," + a.xmax + "," + a.ymax);
b.layers = this.layerOption;
e && (b.layers += ":" + e.join(","));
b.layerDefs = k._serializeLayerDefinitions(this.layerDefinitions);
c = this.timeExtent;
b.time = c ? c.toJson().join(",") : null;
b.layerTimeOptions = k._serializeTimeOptions(this.layerTimeOptions);
if (this.dynamicLayerInfos && 0 < this.dynamicLayerInfos.length) {
var a = r.getScale({
extent: a,
width: this.width,
spatialReference: a.spatialReference
}),
g = k._getLayersForScale(a, this.dynamicLayerInfos),
m = [];
h.forEach(this.dynamicLayerInfos, function (b) {
if (!b.subLayerIds) {
var a = b.id;
if ((!this.layerIds || this.layerIds && -1 !== h.indexOf(this.layerIds, a)) && -1 !== h.indexOf(g, a)) {
var c = {
id: a
};
c.source = b.source && b.source.toJson();
var d;
this.layerDefinitions && this.layerDefinitions && (d = this.layerDefinitions);
d && (c.definitionExpression = d);
var e;
this.layerTimeOptions && this.layerTimeOptions
&& (e = this.layerTimeOptions);
e && (c.layerTimeOptions = e.toJson());
m.push(c)
}
}
}, this);
a = f.toJson(m);
"[]" === a && (a...












Hope it helps 2u, my english is a little bad =).

On the other hand, you can look at the link below to see oficial documentatión.

IdentifyParameters | API Reference | ArcGIS API for JavaScript 3.25