Arcade Form Calculation profile return types are: Date | Number | Text. It will be helpful to also return a Dictionary type. This could be used for ArcGIS Runtime apps, in case a few attributes can be calculate in the same expression.
Thanks
I had this same thought about being able to return more complex objects (dict, feature, geometry, etc.), but it might be weird to have a dictionary return type without a matching dictionary field type.
Arcade supports returning a JSONified string and then a way to read it in as a dict with the fromJSON() function. I use this approach a lot when fetching data from other layers as using featureSetByAnything can be very costly, so if I need multiple fields to fetch data from the same dataset or feature I just delegate the task to a single field that returns a jsonified string and use the result of that field as an in memory lookup resource.
Building it looks like this...
//ASSIGNED TO
// $feature["rsrc_service_info"]
function getServiceInfo() {
var serviceNumber = $feature["service_number"];
var serviceNumberDesc = DomainName($feature,"service_number");
// var serviceNumber = "'02081600.1658"; // TEST VALUE
// var serviceNumberDesc = "'02081600.1658 (Placeholder)"; // TEST VALUE
if (!IsEmpty(serviceNumber) &&
Find('Placeholder', serviceNumberDesc, 0) == -1) {
serviceNumber = Replace(serviceNumber, "'", "");
var sql = "service_number LIKE '%" + serviceNumber + "'"
var fields = ['service_number', 'service_status', 'task_id',
'keyword_id', 'permit_id'];
var mapLayer = 'Service_Orders_Resource_Table'
var fset = FeatureSetByName($map, mapLayer, fields, false);
var ffset = Filter(fset, sql);
for (var f in ffset) {
break;
}
if (!IsEmpty(f)) {
console('Building jsonText');
json = '{"service_number": "' + f.service_number + '", '
+ '"service_status": ' + IIF(IsEmpty(f.service_status), 'null', '"' + f.service_status) + '", '
+ '"task_id": ' + IIF(IsEmpty(f.task_id), 'null', f.task_id) + ', '
+ '"keyword_id": ' + IIF(IsEmpty(f.keyword_id), 'null', f.keyword_id) + ', '
+ '"permit_id": ' + IIF(IsEmpty(f.permit_id), 'null', f.permit_id) + ''
+ '}';
console('JSON Length: ' + Count(json));
console(json);
};
} else {
console(pad + 'Service Number is null or placeholder; return empty json');
};
return json;
};
//START HERE
var pad = '>>> ';
var json = '{}';
return getServiceInfo()
And utilizing it looks like...
//ASSIGNED TO
// $feature["service_keyword"]
console('Set Service Keyword')
var pad = '>>> '
var key = 'keyword_id'
var value = Null;
var json = $feature["rsrc_service_info"];
// var json = '{"service_number": "02081600.1658", "keyword_id": 83880}'; // TEST VALUE
if (!IsEmpty(json) && json != '{}' && Find(key, json, 0) != -1) {
var dict = fromJSON(json)
value = dict.keyword_id
};
console(pad + key + ': ' + value)
return value;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.