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
    • 105

    #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
Working...