0

Trigger on Update not triggering

I want to automatically create some child records in 2 child tables. In the parent table, Trigger on Create successfully creates the required child records in one child table (actually it duplicates some default records that already exist). This worked on a button and then from Trigger on Create as I actually want.

The other child records (in the other child table) cannot be created then, so I thought I'd trigger that process once the required parent fields have been filled in. So in Trigger on Update I set up the criteria and tested, usiing an Alert() to show it's working correctly, when it should and not when it shouldn't.

I then create a button that contains the code to duplicate the appropriate records in the second child table and link them to this parent (as I do for the first child table). This button works perfectly. The child records are duplicated and linked to this parent and immediately populate the table field visible in the parent form. All good so far.

 

I then copy the child record duplication code into the Trigger on Update, replacing the Alert(). So the child records should be automatically created when the criteria are met, just as for the Alert() test. Doesn't work. Nothing appears to happen. No child records are even duplicated, let alone then linked to this parent.

 

I know the trigger is correct (the Alert() test proved that) and the actual code is correct (works on the button). So why does the code not work when triggered using the same criteria as the Alert() test? Is there some restriction that Ninox will not create child records from any Trigger on Update? I don't think I'm the only person to find Trigger on Update has some foibles.

It would be irritating, but I can work around it. However if there is any such restriction, I want to know so I can avoid wasting time on this again in the future. Anyone clarify why Trigger on Update is failing?

11 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    Can we see the code you use in the Trigger?

    • John_Halls
    • 2 yrs ago
    • Reported - view

    With a button you are chosing when to run the code and with a Trigger on create: you are running the code just once but with a Trigger on update: you are running the code on every update so you need to be more rigid about the criteria needed for it to run successfully, and to trap the fact that it has run OK in a flag so it doesn't keep on trying to update again and again. It should look something like

     

    if triggerFlag = false and field1 = "expectedValue1" and field2 = "expectedValue2" then

    << update code here>>

    triggerFlag := true

    end

     

    Regards John

    • UKenGB
    • 2 yrs ago
    • Reported - view

    As I explained, the trigger code is written specifically to only run when appropriate and I have checked this with an alert() so I could be sure it was 100% correct. It runs ALWAYS when required and NEVER when not.

     

    The button perfectly achieves what it is supposed to. It creates the desired child records - perfectly.

     

    The problem is that if the alert() in the Trigger on Update code is simply replaced with the code that is in the button, nothing happens.

     

    I used the the same process for Trigger on Create. Checked that it was triggering (not complicated, not additional criteria to check) and that the button code worked. Then copied the button code into the Trigger. That works. When a new parent is created, the appropriate child records are created.

     

    This however fails with the Trigger on Update. The trigger runs when it should and the code does what it's supposed to, but only when run from a button and not from the Update trigger.  I even included the alert() along with the code copied from the button, so I could see if anything was actually running. However, no alert dialog.

     

    So, when the trigger is only the alert(), it works when it should. If the trigger also contains code to create the child records, it is not run.

     

    I cannot see how to perform a more exact test. Each part works perfectly, 100%. Put them together? Nah. Nothing.

     

    I'll reply again with the code.

    • UKenGB
    • 2 yrs ago
    • Reported - view

    This is the code I used to test the Update Trigger:-

    if (number(Cylinders) = 1 or (Cylinders and Configuration)) and Type and not 'Numeric spec data🔗ⁿ' then
    alert("get params")
    end

    That works, so when changing anything, if those criteria are met, the alert dialog is displayed.

    The button code is:-

    let thisEng := this;
    let thePars := (select 'engineⓅs' where number(Id) < 10 and Parameter);
    if lower(text(Type)) = "electric" then
    thePars := thePars[lower(text(Parameter)) = "weight"]
    else
    if number(Cylinders) = 1 then
    thePars := thePars[lower(text(Parameter)) != "angle"]
    else
    if number(Configuration) != 5 then
    thePars := thePars[not (lower(text(Qualifier)) = "cylinder" and lower(text(Parameter)) = "angle")]
    end
    end
    end;
    for p in thePars do
    let d := duplicate(p);
    d.('Engine🔗¹' := thisEng)
    end

    I previously tested the above just creating a text output to be sure it was basically correct, and then changed to the above which actually creates the child records. It works, correctly, every time, on the button.

     

    Replace the alert() line in the trigger with the above button code and the code is not executed. 

     

    The only thing that occurs to me is that the trigger checks for there being no child records and if that's the case, it creates some. Is Ninox being too clever and looking ahead, sees that there would be records if it was executed, which would then fail the original check and so doesn't execute the tigger? It does seem rather coincidental that the code to execute would change the trigger condition. Doesn't seem like the correct behaviour, but is that possibly what is causing Ninox to not trigger?

    • Fred
    • 2 yrs ago
    • Reported - view

    Interesting that same code works in Trigger on Create and in a button but doesn't work on Trigger on Update.

    • John_Halls
    • 2 yrs ago
    • Reported - view

    OK, after extensive testing I was able to mimic the behaviour you were experiencing (button vs trigger etc) and find the culprit. I have to concur that it's very odd. It comes down to the use of duplicate. It was adding child records but not linking them to the parent. Swap this out and use create instead you will be able to get it to work. You will need to update the fields of the child at the same time as updating the link.

     

    for p in thePars do
    let d := create 'engineⓅs';

    d.Text1 := p.Text1;
    d.('Engine🔗¹' := thisEng)
    end

     

    Regards John

    • UKenGB
    • 2 yrs ago
    • Reported - view

    In my case, it appears to not be triggering at all. I tried including an alert(), but it was never displayed. Mind you, did I read something somewhere that Trigger on Update simply won't show an alert() even if included? Or did I dream that?

     

    However, No child records were being created. First thing I did when troubleshooting was to check the child table and no records has been added. So they weren't being created but not linked.

     

    In the end I decided the use of a button was better interface design, so this is no longer an issue, but it would be interesting to find out exactly what the bug is. Unless anyone can put forward a valid reason why this behaviour is correct?

    • UKenGB
    • 2 yrs ago
    • Reported - view

    Ignore my first comment about no alert() in Update Triggers. I was using that when first testing, so they definitely do display.

    • John_Halls
    • 2 yrs ago
    • Reported - view

    Did you try swapping out duplicate for create? I think you will find duplicate is the source of the bug. I can show you my test code if you would to see it.

    • UKenGB
    • 2 yrs ago
    • Reported - view

    I think we need to pass this to support so they can try to fix it sometime.

    • Janat_chwezi
    • 2 yrs ago
    • Reported - view

    +27784103651 Powerful love spells lost love spell caster in Armenia, Australia, Austria, Azerbaijan, The Bahamas, Bahrain, Bangladesh, USA
    Powerful love spells lost love spell caster in Armenia, Australia, Austria, Azerbaijan, The Bahamas, Bahrain, Bangladesh, USA

    +27733404752 Top WITCHCRAFT /Best/Famous Psychic in London, Spiritual Healer, Black Magic Love Spells, Voodoo,

    HOW TO CAST A LOVE SPELLS THAT WORK IMMEDIATELY

    How To Cast A Death Spell On Someone,

    Death Spells That Work Overnight to kill wicked Step-dad/ Stepmom

    Death Revenge Spell on wicked friends,

    Voodoo Death Spells to kill Enemies

    Black Magic Spells To Harm Someone,

    Black magic death spells on ex-lover,

    Revenge instant death spells on uncle+27784103651

    Dr mama janat powerful instant death spells online instant spell that works fast in USA, UK, Kuwait, Germany, Asia, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece, Dr MAMA janat 7demons Voodoo death spell casters spell to make someone sick and die without delay.

    https://chwezilovespells.com

    +27784103651

Content aside

  • 2 yrs agoLast active
  • 11Replies
  • 735Views