Hi,
I haven’t figured out how to properly process data with an action before opening a view.
For example, I want to automatically block a delivery if the customer hasn’t already paid. My script changes a custom boolean field, which is then used to prevent the user from planning or completing the delivery.
Putting the action in the view’s onLoad has a major drawback: if I modify the data with setAttr, I need to save the record, and saving requires the user to have the appropriate permission.
If I modify the data directly in the database with:
__repo__(myRepo).save(current)
the data is correctly updated in the database, but the view is not refreshed. I tried using setReload, but this causes the view to flicker, which is not really pleasant for the user.
Another possibility would be to call the action before every action-view or widget that can open this view, but this is rather cumbersome because I would have to identify and modify every place where the view can be opened.
Currently, I put my action in onLoad. It checks whether the current user has permission to save the record, and if they do, the script is executed and the record is automatically saved.
However, I am not really satisfied with this approach because some users do not have write permission, so the action-script is not executed at all.
I think it would be very convenient to have a view parameter, for example:
<form ... beforeLoad="action-my-script">
which would execute an action before the view is displayed to the user, with permissions determined by the action itself rather than by the user’s write permissions on the view.
Is there currently a recommended way to achieve this ?