Trigger after update & Alert anomaly
Community -
I developed a database in the Mac app. The database is deployed on the web.
There are 2 fields in a table that have code entered into the 'Trigger after update field'. The code checks the input before commiting the entered data. If the data input violates the trigger conditions an Alert is shown and then after the Alert is cleared the data is cleared from the field.
All this works fine in the Mac app. However, once deployed on the web the Alert is not displayed.
That is, when data is input the Trigger checks the input and if the conditions are violated the input is deleted as expected but, the Alert is never displayed -- when the data has been input and either the enter key or a click in white space the screen sort of blinks and a moment later the violating data is cleared as expected.
Thinking I was clever, in the web database I changed the binding to 'Per record in memory (browser)' for the 2 fields and the Alert is dispayed as expected but, to my momentary panic I noticed that all of the data in the 2 fields were "gone" -- yikes!
Fortunately, when I changed the binding back to the default 'Per record in server (default)' the data were "restored".
I see that there is a table level Trigger after update setting and perhaps this is the proper place to check the input and show the Alert properly but, I'm unsure as to what the code would look like to check the fields simultaneously or independently from the table level.
In my mind, since I currently have the trigger at the field level the fields are checked/triggered independently.
Here is the field level trigger code ( again this works fine in the app and the web but, the Alert is not displayed when deployed on the web )
Thank you.
MATERIAL OUT field — trigger after update
let inv := Material.'Inventory Level';
let mtout := 'MATERIAL OUT';
switch true do
case mtout < 0:
(
alert("Negative values not allowed");
'MATERIAL OUT' := null
)
case inv >= 0:
'MATERIAL OUT'
default:
(
alert("MATERIAL OUT value " + 'MATERIAL OUT' +
" is more than Inventory amount.
Please enter valid MATERIAL OUT value");
'MATERIAL OUT' := null
)
end
MATERIAL IN field — trigger after update
let ctinv := Material.AMOUNT - Material.'Inventory Level';
let mtin := 'MATERIAL IN';
switch true do
case mtin < 0:
(
alert("Negative values not allowed");
'MATERIAL IN' := null
)
case ctinv >= 0:
'MATERIAL IN'
default:
(
alert("MATERIAL IN value " + 'MATERIAL IN' +
" roll up is more than Inventory amount.
Please enter valid MATERIAL IN value");
'MATERIAL IN' := null
)
end
7 replies
-
I think you are running into the issue that Triggers happen at the server level so no alerts show to the end user. It is like wrapping your code with [do as server].
Of course it worked on your macOS app since the app is the server. Someone posted a nice summary once that I can't find about what happens at server level and what is at user level.
-
Here you find the execution context: https://docs.ninox.com/en/script/transactions/execution-context
-
thanks for the info but I'm not sure how that affects my situation or how to use that info.
thanks - perhaps I should create a couple of extra fields and turn them on / off to "simulate" the Alert behavior.
Feeback is much appreciated!
-
I tried using the 'do as server' and 'do as deferred' to wrap the trigger script but no joy; which you probably knew without even trying!
Yes, as discussed, I'm puzzling thru a work around using button(s) and supporting unseen field(s) using lots'o boolean logic to achieve the desired results. At the end of the day UX is all about making the DB simple,clear, consise & bomb-proof for non-DB developers.
A shame the alert doesn't work within the trigger functionality since that's a simpler more elegant solution.
Thank for the words of wisdom!!
Content aside
- 9 mths agoLast active
- 7Replies
- 134Views
-
3
Following