Foreign link to text list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muulox
    Member
    • Jan 2022
    • 51

    #1

    Foreign link to text list

    Hello, I need a little help
    I have an entity called “Contracts”, which includes a foreign relation field to the “basecontracts” entity, where we select the basecontracts associated with each contract.
    In the same “Contracts” entity, I have a text field called “listacontracte”, where I want to display the names of all selected basecontracts, separated by commas, using a formula.
    What would be the correct formula to use in the Before Save section to achieve this?
    I need to extract all the basecontracts names separated by commas to send the list in e-mail and sms.

    Thank you!
    Attached Files
  • lazovic
    Super Moderator
    • Jan 2022
    • 1053

    #2
    Hi muulox,

    Please try using the following formula script:
    Code:
    $contractBazeIds = record\findRelatedMany('Contract', id, 'basecontracts', 1000, 'createdAt', 'desc');
    
    $contractBazeNames = list();
    $i = 0;
    
    while ($i < array\length($contractBazeIds)) {
        $contractBazeId = array\at($contractBazeIds, $i);
        $contractBazeName = record\attribute('ContractBaze', $contractBazeId, 'name');
        $contractBazeNames = array\push($contractBazeNames, $contractBazeName);
        
        $i = $i + 1;
    }
    
    listacontracte = array\join($contractBazeNames, ', ');
    Please note that the words Contract, ContractBaze, listacontracte and basecontracts may differ. You need to check in Entity Manager what exactly your fields, entities, and the relationships between them are called.

    Comment


    • muulox
      muulox commented
      Editing a comment
      Thank you! It is working!
Working...