Hello,
I am using Enterprise 10.9.1. I have created a Field Map App and using Collector on desktop. When a new complaint is entered in the app, I would like for the total count of complaints to automatically update. But it doesn't.
In the mapviewer/Enterprise, I created a new field and used the calculate function to count all complaints. When I enter the calculate function it works great - thanks to this forum. But when I add a NEW complaint in the app, the total count doesn't update. I have to go back to map viewer and re do the calculate function.
I assumed this would update automatically, but after reading about SQL and the calculate function it states "one of the most common calculations you perform is to derive a new numeric value based on existing values in your feature layer." I think existing values is the key word. I want it to update on new values.
Any suggestions. It was suggested to use python as a script, but since I am using map viewer in the Enterprise that is not an option. Plus only a beginner at python.
Has anyone else come across this? Any idea what to do? Thank you!
Solved! Go to Solution.
By the way, I don't know what's going on with the map viewer...
Did you try adding this as a custom expression to the feature popup?
Hello,
Thank you so much. I am learning a lot! I appreciate it. Yes, it did work in the configure pop up! Dashboard not quite getting it. Thank you for your help on the dashboard, I have viewed a lot of videos but most skip over the easy stuff and its assumed I know how to do this.
This is what it looks like now, but indicates 'unable to execute Arcade script"
You're so close! Just a minor tweak and you'll have it.
In the return, you only need to set the attribute "total" to the variable "total". In other words:
return {
attributes: {
total: total
}
}
And then put "{expression/total}" in the line item template down below the code section.
Thank you so so much. It worked!!! But now I have another issue. In the dashboard I am using the list element and I want to sort the complaint count from high to low, but since the expression doesn't create a field I can't use the function that is in the element. After research I found I could use an order by on the FeatureSetByName, however, in the dashboard that isn't an option to use the FeatureSetByName. I see there is a Sort in the dashboard - Sort ( inputArray , comparator ) returns { Array }. Would it accept expression/total? Thinking out loud, I want it to sort my expression and return any greater than 5, but I am not sure how to make this work in Arcade. Help again would be appreciated. Also what does this mean {Array}. Here is my stab at it. Thank you.
Sort (expression/total, > 5 ) returns { Array }
Ah, well now we've crossed into the realm of Data Expressions, which are a different sort of animal. It can be a bit to wrap your head around when you're new to them, but I'm sure they'll quickly make more sense. You can see some examples here: https://github.com/Esri/arcade-expressions/tree/master/dashboard_data
var portal = Portal('your portal url')
var fs = FeatureSetByPortalItem(
portal,
'item id of service',
0, // or other layer index, if multiple layers
['*'],
false
)
// create output array of features
var feats = []
// iterate over featureset
for (var f in fs){
// calculate sum
var sum_fields = [
f['some_field'],
f['another_field'],
etc
]
var total = 0
for (var s in sum_fields){
If (!IsEmpty(sum_fields[s])){
total += 1
}
}
// create feature object
var feat = {
'attributes': {
'total': total
}
}
// add feat to feats array
Push(feats, feat)
}
// Create FeatureSet JSON from feats array
var out_dict = {
fields: [
{name:'total', alias:'Number of Complaints', type:'esriFieldTypeInteger'}
],
geometryType: '',
features: feats
}
// Convert JSON to true featureset and return
return FeatureSet(Text(out_dict))
To add a Data Expression to your dashboard, you can find the "add new data expression" button when you're adding a new widget or configuring the data source of an existing widget.
Once you get this written up and working, the resulting layer in your dashboard will behave as if the "total" attribute were a legitimate field in the table, allowing you to sort and filter to your heart's content.
Taking this a step further, supposing you wanted this list to interact with other widgets, you may need to include something like the objectID in the feat attributes dict, as well as in the out_dict fields list.
Thank you for all your help. I am going to check into the above but first I have to figure out the IFF function. I appreciate all your help.
Hello jcarlson,
Thanks to you I am working on this data expression. I literally have included your script from above, but I am getting an error 'unexpected end of input'. I have tried various things but nothing works. Do you see what I am doing wrong? This expression is where I am doing a total count of complaints for a homeless camp, now I want to create it as its own attribute. I am in the dashboard and I selected serial chart, new data expression.
var portal = Portal("https://##############/portal")
var fs = FeatureSetByPortalItem(
portal,
'058330e0c9204c53b208400dd4b126c6',
0,
['*'],
false
)
var feats=[]
for (var f in fs){
var sum_fields = [
$feature.complaint,
$feature.contactinfo,
$feature.complaint2,
$feature.complaint3,
$feature.complaint4,
$feature.complaint5,
$feature.complaint6,
$feature.complaint7,
$feature.complaint8,
$feature.complaint9,
$feature.complaint82,
$feature.complaint11,
$feature.complaint12,
$feature.complaint13,
$feature.complaint14,
$feature.complaint15
]
var total = 0
for (var s in sum_fields){
If (!IsEmpty(sum_fields[s])){
total += 1
}
}
var feat = {
'attributes': {
'total': total
}
}
Push(feats, feat)
var out_dict = {
fields: [
{name:'total', alias: 'Number of Complaints', type: 'esriFieldTypeInteger'}
],
geometryType: '',
features: feats
}
return FeatureSet(Text(out_dict))
_______________________________________
Thank you very much. Annette