Record in n:n middle table not updated correctly by before save script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agri
    Senior Member
    • Mar 2021
    • 109

    #1

    Record in n:n middle table not updated correctly by before save script

    Hi,
    I need some help with a before save script:

    Setting:
    - an entity named person
    - an entity named occasion
    - a n:n relation between person and occasion
    - some data saved in middle table ('CPersonOccasion') of n:n relation. Here: field 'contacedBy'
    - a n:1 relation from person to person
    - in entity person, fields personParent (n:1) and occasion (n:n)
    I try to save the contents of field person.personParent into a field CPersonOccasion.contactedBy in middle table, using formula in before save script.

    Script is before save in entity person:
    $poId = entity\attribute('id');
    $poContact = entity\attribute('personParentName');
    $poRelId = record\findOne('CPersonOccasion', 'createdAt', 'desc', 'personId=', $poId);
    record\update('CPersonOccasion', $poRelId, 'contactedBy', $poContact);


    If I change either personParent or occasion fields and save, nothing happens. BUT: after having saved the person record, immediately I put the very same script into formula sandbox and execute. And, TADAA - works perfectly!
    Seems, the script only regards saved data. As there is no after save script - how can I solve this?

    ​Regards
  • Marcel
    Junior Member
    • Jul 2025
    • 6

    #2
    Hi,

    I guess updating an related item is not causing the object to be saved. As I know you need to use a hook script for that.
    I also got the same behavior with my relation counting after save script. If I change something in my object directly (Fields on the object - Without relation) it´s working. When I only add/update or remove a relation object, the after save script is not running.

    I hope that helps a bit.

    Regards

    Comment

    • agri
      Senior Member
      • Mar 2021
      • 109

      #3
      Hi Marcel,
      could you provide a hook script of yours as an example?
      Regards

      Comment

      Working...