Select to view content in your preferred language

Need to replace value for the attribute (using domains and don't want to see domain value)

527
1
03-24-2022 06:34 PM
lxd
by
Regular Contributor

Hello, 

Not a developer and find it hard to work this out.

I have this code:

queryTask.execute(query, lang.hitch(this, function(results) {
DataReport = array.map(results.features, function (feature) {
Data= [feature.attributes["PLANNEDORCOMPLETED"],feature.attributes["AREAHA"],feature.attributes["ACTIVITYTYPE"],];
dataReport2.push(Data);
});
}));

feature.attributes["PLANNEDORCOMPLETED"] - is a field with coded domain, so my output looks like 1,2,3,1,2,3 (these are the values of the domain, see screenshot below). I can't work out how to replace numbers with actual descriptive values of the domain names.

I am not necessary need to connect back to the dataset, even if I can add somewhere in my code: 

if 1, use "tomato, if 2, use "potato", etc. Not sure how and where...

 

I also would like to add an extra row at the end to populate the sum of all numbers. I got the value for the sum but don't know how to add extra line in the Data variable.

Any help greatly appreciated! 

 

screen1.png

 

screen2.png

0 Kudos
1 Reply
SumitZarkarCT
Occasional Contributor

@lxd 

From your question it is not clear what framework you are using to develop this code.

However, I assume you are using WebAppBuilder and looks like you are creating date for the Report dijit in jimu core to print the report.

If you are using Web App Builder you can use jimuUtils method to get the values for domain like this

// this.featureLayer is the layer which is used for querying
// fieldName which has coded domain
// attributes - Attributes object of the fetched feature
var layerDefinition = jimuUtils.getFeatureLayerDefinition(this.featureLayer);
var result = jimuUtils.getDisplayValueForCodedValueOrSubtype(layerDefinition,fieldName,attributes);
//In result.displayValue you willl get the displayValue for the code
result.displayValue;

 

And to add a new row in the data to print sum you can push one row in your dataReport var like this:

dataReport2.push(["",totalSum,""])

0 Kudos