0

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

null
    • Fred
    • 2 mths ago
    • Reported - view

    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.

    • Ninox partner
    • RoSoft_Steven.1
    • 2 mths ago
    • Reported - view
    • spinner_7580
    • 2 mths ago
    • Reported - view

     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!

      • Fred
      • 2 mths ago
      • Reported - view

      Steven's link shows you where the action happens depending on where you make the call. So it says a Trigger after update happens at the server level for browsers and at the client level for apps.

      Which means any alerts() that you write will not appear to the end user if the action happens at the server level. Something you need to be aware of when you develop on the app but implement in the cloud.

      thanks - perhaps I should create a couple of extra fields and turn them on / off to "simulate" the Alert behavior.

      that is an interesting idea.

      Or you take the functions of the Triggers and put it in a button, so you can show dialogs or alerts? Triggers are places, in my opinion, for things to happen in the background.

    • spinner_7580
    • 2 mths ago
    • Reported - view

    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!!

      • Fred
      • 2 mths ago
      • Reported - view

      Sorry if I gave the impression to wrap the script in a do as server.  That will definitely make any script with an alert() function not show up. Just follow the chart provided to figure out if alerts will show up or not.

      Don't know if you have looked at switches but I find them easier than lots of if statements.

      • spinner_7580
      • 2 mths ago
      • Reported - view

        Yep - switches are nice.  If you look at the trigger code above you'll see I used switches 👍

Content aside

  • 2 mths agoLast active
  • 7Replies
  • 83Views
  • 3 Following