adding followers to a record via formula language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Senior Member
    • Aug 2025
    • 294

    #1

    adding followers to a record via formula language

    I’m trying to add followers via Formula in EspoCRM, but I think the example I was given might not be correct.

    ChatGPT suggested the following:

    Code:
    Add a single follower
    entity\addFollower('USER_ID');
    
    Add multiple followers
    entity\addFollowers(list('USER_ID_1', 'USER_ID_2'));
    
    Example (current user)
    entity\addFollower(entity\fetch('User', 'currentUserId'));
    
    Common real-world pattern (add assigned user as follower)
    entity\addFollower(assignedUserId);
    However, I can’t find any documentation or evidence that these Formula functions actually exist in EspoCRM.

    From what I can tell, this may not be valid Formula syntax and could be a mix of pseudo-code or backend logic rather than something available in Formula itself.

    What I’m trying to achieve


    I need to automatically add followers when certain conditions are met (e.g. sales need to follow a new account).

    Any guidance would be appreciated.
  • a.slyzhko
    Senior Member
    • Oct 2023
    • 129

    #2
    There is no such formula function. You can write something like that to achieve the goal

    PHP Code:
    $entityType = 'EntityType';
    $entityId = 'ENTITY_ID';
    $usersIds = list('USER_ID_1', 'USER_ID_2', 'USER_ID_3');
    $size = array\length($usersIds);
    $i = 0;
    
    while ($i < $size) {
        $userId = array\at($usersIds, $i);
        
        $exists = record\exists('StreamSubscription', 'entityType=', $entityType, 'entityId=', $entityId, 'userId=', $userId);
        
        if (!$exists) {
            record\create('StreamSubscription', 'entityType', $entityType, 'entityId', $entityId, 'userId', $userId);
        }
        
        $i = $i + 1;
    } 
    

    Comment


    • jamie
      jamie commented
      Editing a comment
      That is quite a workaround, but very usable, thanks
Working...