Problem/Bug with CONTEXT()

OliverDahl
Participant IV

Hi!
When using CONTEXT() in security filters, the “Host” and “View” parameters doesn’t work correctly.

CONTEXT("Host") = "Server" returns TRUE when previewing the app in the emulator
CONTEXT("Host") = "Browser" returns FALSE when previewing the app in the emulator
CONTEXT("View") = "" returns TRUE when previewing the app in the emulator

The documentation states:

Host : Gives Browser if the app is running in a browser or the app editor’s emulator, Device if a native app, or Server if used from an AppSheet server (e.g., in a workflow or report).
View : The name of the view currently displayed to the user, or blank if no view is currently displayed (e.g., in a workflow or report).
CONTEXT() | AppSheet Help Center

If I understand it correctly, the reason behind this error is that the security filter is run on the AppSheet server, and not local on the device. But this limits the functionality, because I may want for instance to sync some records when using a phone app, and other records when using the browser. And the documentation doesnt state that is doesn’t work.

Any suggestions? @Steve

0 10 460
10 REPLIES 10

Create usersettings using app formula of Context(host).
Then on your table security filter settings, use that user settings for slice condition.
Try it out.

Result of usersetting calculation is based on “client”
Then when user launch app, we are able to access this value, then use this value to filter your table on sync.

Aha, thanks for the tips! Thats clever!
But that usersetting will not be set when for instance a workflow or report is running? If I want some rows to only be available when CONTEXT(“Host”)=“Server”, how can I do that?

On workflow (currenlty we call BOT) on event setting, you can turn on / off bypass filter.

Thats right! I am just used to still call them workflows
I see that my explanation was sligtly off. I am triggering some actions via the Appsheet API from a webserver, and I want some rows to be available then, and thats why I would like the CONTEXT(“Host”) =“Server” to work in this instances. Becuase when running them from outside Appsheet, I am not able to bypass the filter. But I can choose which user to run it as, but I hoped to avoid to hard code what user in the web server routine.
But I have another workaround I can use Thanks for helping!

But maybe it would be possible to warn users in the formula editor or documention that CONTEXT() in security filters may not work?

I m not familiar with Context(host) = server, I never use in my app before.
But bypass security filter on/off settings couple with this technique should solve your own issue, I reckon.

Steve
Participant V

Your expectation tha the documentation identify every possibility that doesn’t work is unrealistic, if not absurd.

Sorry! I did not mean to criticize! I just found this really hard to figure out my self, and thought it might be helpful to others.

If CONTEXT("View") indeed doesn't work in a security filter, it would have saved me some time if the documentation regarding CONTEXT() or Security Filters explained that (or, if they do, that it were easier to find, because I haven't found it). I'm experiencing challenges getting that to work, and it's not clear to me whether that's simply not valid or I'm doing something wrong.

I infer from this thread that a security filter expression can reference User Settings values from the local device, but otherwise cannot reference any information that's not on the server, such as CONTEXT("View") and CONTEXT("Host"). If something like that is accurate, it would be helpful to add to the documentation.

No, CONTEXT("View") cannot work in Security Filters.

Evaluating Security Filters is part of a the entire data loading/syncing process, which only occurs when data changes. Navigating between views is an entirely separate process, which does not require changing data, and wouldn't even be able to trigger the re-evaluation of Security Filters.

 

Both UserSettings and CONTEXT("Host") can certainly work in Security Filters. (Edit: see comment below)

I was partially mistaken above.

You can use CONTEXT("Host") in a Security Filter, but it is meaningless and useless, because Security Filters are evaluated by the server, just like Virtual Columns, so CONTEXT("Host") will always return "Server" in such cases.

Top Labels in this Space