Visual Builder

Get Involved. Join the Conversation.

Topic

    Stephen Bryant
    Field Level Update Trigger updates field only onceAnswered
    Topic posted November 15, 2019 by Stephen BryantBronze Trophy: 5,000+ Points, last edited November 15, 2019, tagged Business Objects, Custom Code, Groovy 
    14 Views, 6 Comments
    Title:
    Field Level Update Trigger updates field only once
    Summary:
    Field Level Update Trigger on BO only updates field when record is created
    Content:

    Hello,

    I have a very simple trigger in one BO that executes always.  When a field is updated (treasurySymbol), I grab another field from a related BO (attributeOne).

    This works fine when the record is created but updates do not work.

    It is an update trigger so I am a little confused here.  When I change the treasurySymbol field, the attribute1 field does not change.

    Here is the simple code generated:

    // Field Trigger Beginning 
    println 'Field Trigger started: testUpdateTrigger, business object: fvBeTrxHdrs, field: treasurySymbol';

    try {

      // Always Execute Criterion (Always Execute)
      alwaysExecuteCriterion_1: {
        // Action Group (Action Group)
        test = {
        treasurySymbolObject.attributeOne
        }.call();

      }

    } finally {

      // Field Trigger End 
      println 'Field Trigger ended: testUpdateTrigger';

    }

    Am I missing anything?  I've tried setAttribute, isAttributeChanged without success.

     

    Thank you,

    Steve

    Version:
    19.3.1.2

    Best Comment

    Shay Shmeltzer

    What does the BO log window show when the trigger is executed?

    Also - can you explain your code:

        test = {
        treasurySymbolObject.attributeOne
        }.call();

    If you just want to get a value from related object and update a field in the existing one it will look something like:

    // Trigger Beginning 
    println 'Trigger started: updateTrigger, business object: Employees, event: BeforeUpdate';

    try {

      // Always Execute Criterion (Always Execute)
      alwaysExecuteCriterion_1: {
        // Action Group (Action Group)
        name= name + departmentObject.department;

      }

    } finally {

      // Trigger End 
      println 'Trigger ended: updateTrigger';

    }

    Comment

     

    • Shay Shmeltzer

      What does the BO log window show when the trigger is executed?

      Also - can you explain your code:

          test = {
          treasurySymbolObject.attributeOne
          }.call();

      If you just want to get a value from related object and update a field in the existing one it will look something like:

      // Trigger Beginning 
      println 'Trigger started: updateTrigger, business object: Employees, event: BeforeUpdate';

      try {

        // Always Execute Criterion (Always Execute)
        alwaysExecuteCriterion_1: {
          // Action Group (Action Group)
          name= name + departmentObject.department;

        }

      } finally {

        // Trigger End 
        println 'Trigger ended: updateTrigger';

      }

      • Stephen Bryant

        Shay,

        Unfortunately, the log shows that the trigger ran successfully but when I check out the field to be updated, it does not update to the new value.  In other words, it is as if the trigger has no effect.

        I will continue to investigate.

        The code above is simply using the object relationship between the two BOs.  

        Thanks,

        Steve

      • Stephen Bryant

        Shay,

        I added another BO just to test relating it to the an existing BO.

        The same thing happens.  This is strange.

        Here is the code (generated)

        // Field Trigger Beginning 
        println 'Field Trigger started: testTrig, business object: TestTrigger, field: tAS';

        try {

          // Always Execute Criterion (Always Execute)
          alwaysExecuteCriterion_1: {
            // Action Group (Action Group)
            test = {
            tASObject.treasurySymbol
            }.call();

          }

        } finally {

          // Field Trigger End 
          println 'Field Trigger ended: testTrig';

        }

        • Shay Shmeltzer

          I don't see where you are updating a field here.

          Is the field that you are trying to update called test? If so can you just have this code in your groovy:

           

          test = tASObject.treasurySymbol

          Maybe add a println("Hello Im here") before that so you can see if the trigger is invoked when you look at the BO log window. 

           

          • Stephen Bryant

            Shay,

            Yes the field is called test. 

            I also used println statements to see if the trigger was firing and it was.  

            I even made sure the values were changing with variables but the only thing that is not happening is it will not update the test field. Again this works on the first creation of the record but after that it will not work. It does not seem to update the test field if the record is already in the table. 
             

            steve

    • Stephen Bryant

      Shay,

      I created two object level triggers, one for Before Insert, and the other for Before Update and that all works.

      I was originally using a field level trigger which defaults to Before Insert and there is no way to change it.

      Steve