Update hosted layer view definition w topfilter to show only most recent record

3861
19
Jump to solution
04-07-2020 08:47 AM
JayJohnsonWashoeCounty
Occasional Contributor III

I have a hosted table with many records and would like to create a view layer from this that only shows the most RECENT record. 

I've created a view layer and attempted to update the view definition using the TOPFILTER via the admin API.

Original Layer Definition:

{
"adminLayerInfo" : {
"tableName" : "db_4176.user_4176.CASES_TABLE_CASES_TABLE", "geometryField" : null,
"xssTrustedFields" : "",
"viewLayerDefinition" : {
"sourceServiceName" : "Cases_Table",
"sourceLayerId" : 0,
"sourceId" : 984,
"sourceLayerFields" : "*"
}
},
"id" : 0,
"name" : "Cases_Table",
"type" : "Table",
"isView" : true,
"isUpdatableView" : true,
"sourceSchemaChangesAllowed" : true,
"displayField" : "",
"description" : "",
"copyrightText" : "",
"defaultVisibility" : true,

ETC...

I think I need to insert something like the following, but can't get it to work successfully:

"viewLayerDefinition" : {
"topFilter" : {
"orderByFields" : "reportdt ASC",
"topCount" : 1
}

}

Does anyone have an example of successfully using topFilter (or some other method) to filter a layer view down to just the most recent record?  This is in support of a COVID-19 project.

Thanks

Jay

Jay
Washoe County GIS
0 Kudos
19 Replies
KhaledHassen
Esri Contributor

That looks right to me. I have recently fixed an issue related to topfilter. The fix will be available next week as part of online feature service update. So please try it again with the update.

If it is the same bug I have fixed, then if you retry apply the topfilter. It will finally work. So please try it again another time and see if this is fixed. If not, please wait until next week for the fix. 

0 Kudos
LiamHarrington-Missin
Occasional Contributor II

Thanks @KhaledHassen, I'll wait a week and have another crack.  

I'm curious, a work around that I attempted, given my fear of all things API, was to use the "join" analysis tool (in webmap classic not new, so I can create the feature view instead of a feature layer) and create a join to itself. 

Then in subsequent settings, I'd use a one-one-join around StaffEmail and use the FixTime to determine which record is retained... 

This would be a cheeky workaround admitedly and it doesn't work but I'm not sure why it doesn't work.  

Liam
0 Kudos
LiamHarrington-Missin
Occasional Contributor II

Hi @KhaledHassen,

I'm still not seeing the desired behaviour I want and can't figure it out.  Help.  

I've created a test feature service that shows what data architecture I have.  You'll see 11 records, of which there are five unique entries in the "Email" col.  I want to create a feature view that shows only the most recent records for each email address.  E.g. the feature view will show 5 records, each showing the record that corresponds with the most recent "Fix Time" per email. 

Everything I have tried to date is simply showing me the original 11 entries.  

Liam
0 Kudos
KhaledHassen
Esri Contributor

Hi Liam,

I think you should be able to create a view with the topfilter for this service. Can you pl. provide us with the steps to create the view in our side based on this data. We can try to repro it. I think the step that should work as follows:

- Create an empty view

- Call add to definition and link the view to the source

- Use update definition to change the topfilter.

Thanks

 

Khaled

0 Kudos
LiamHarrington-Missin
Occasional Contributor II

Really appreciate the the prompt response @KhaledHassen, This is driving me nuts, I'm sure it's a user error.

I screen recorded the, clearly incorrect, process I am following to try and achieve this and below is the code snippet.  Any insights would be greatly received. 

Cheers

Liam

{
"viewLayerDefinition" : {
"sourceServiceName" : "Check_In_testDataset",
"sourceLayerId" : 0,
"sourceLayerFields" : "*",
"topFilter" : {
"orderByFields" : "Fix_Time DESC",
"groupByFields" : "Email",
"topCount" : 1
}
}
Liam
0 Kudos
KhaledHassen
Esri Contributor

Hi Liam,

Can you pl. try only the topfilter.

{
"viewLayerDefinition" : {
"topFilter" : {
"orderByFields" : "Fix_Time DESC",
"groupByFields" : "Email",
"topCount" : 1
}
}


Thanks

 Khaled 

0 Kudos
LiamHarrington-Missin
Occasional Contributor II

No joy @KhaledHassen.  I tried it with different combinations of "ASync" and "Format", since I'm clueless about what they mean or do.  Happy to jump on a screen share if you want to fasttrack troubleshoot? Just private msg. me.  

Liam
0 Kudos
KhaledHassen
Esri Contributor

Liam,

I have watched the video. From what I see, you are applying updateDefinition to the feature service and not the layer. You need to go to the layer and set the topfilter on the layer using the layer updateDefinition. You cannot update topfilter in feature service updateDefinition API.

LiamHarrington-Missin
Occasional Contributor II

excited-minions-gif.gif

 There it is.  User error of course.  Working a treat now.  Thanks so much @KhaledHassen!

Liam
0 Kudos
FarmersBranchBrian
New Contributor II

@KhaledHassen This topFilter trick has been invaluable for me in various projects.  It's an especially neat trick for handling parade routes and the current location of various participants in the parade.  We use QuickCapture to stream point data to the underlying Feature Layer and then topFilter to limit it to the most recent feature.

I have noticed something in my most recent project that I thought I might bring to your attention.  The "groupByFields" parameter seems to only work when the field provided is a text field.  I recently tried using a GUID field and the definition update simply would not take.  The moment I changed the groupByFields property to a text field, everything worked fine.  I have not experimented with other field types.  Is this limitation by design or simply a coincidence because of how topFilter is currently implemented on the backend?

0 Kudos