Announcement

Collapse
No announcement yet.

Adding a @user team to a unit when mentioning a user on stream

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding a @user team to a unit when mentioning a user on stream

    Hi,
    is possible to add User team mentioned on the stream?
    Now, when someone mentions a user and the user doesn't have access to the entity, they don't get a notification about mentions.

  • #2
    Hi Enju,

    You can use Workflow with a formula for some solution to this problem.

    The only thing is that with such a solution, attachments need to be sent to the stream without mentioning the user. This nuance can be improved in any case.
    Also, please note that working with Workflows is available only if you have an extension Advanced Pack.

    Create a Workflow with Entity Type Note and Trigger Type After record created. Select the Action Execute Formula Script and paste this formula:
    Code:
    $noteId = entity\attribute('id');
    $parentId = entity\attribute('parentId');
    $parentType = entity\attribute('parentType');
    $post = entity\attribute('post');
    
    $usernameCatch = string\match($post, '/@\S*/');
    $username = string\substring($usernameCatch, 1);
    $usernameId = record\findOne('User', 'createdAt', 'desc', 'userName=', $username);
    $userTeam = record\attribute('User', $usernameId, 'teamsIds');
    
    record\relate($parentType, $parentId, 'teams', $userTeam);
    
    ifThenElse(
    record\count('Note', 'type=', 'Post', 'parentId=', $parentId, 'post=', $post, 'parentType=', $parentType) == 1,
    record\create('Note', 'type', 'Post', 'post', $post, 'parentType', $parentType, 'parentId', $parentId) && record\update('Note', $noteId, 'deleted', '1')
    );
    Last edited by lazovic; 07-01-2022, 06:21 PM.

    Comment


    • #3
      Yes, I have advanced pack. Thank you so much!

      Comment


      • #4
        Originally posted by lazovic View Post
        Hi Enju,

        You can use Workflow with a formula for some solution to this problem.

        The only thing is that with such a solution, attachments need to be sent to the stream without mentioning the user. This nuance can be improved in any case.
        Also, please note that working with Workflows is available only if you have an extension Advanced Pack.

        Create a Workflow with Entity Type Note and Trigger Type After record created. Select the Action Execute Formula Script and paste this formula:
        Code:
        $noteId = entity\attribute('id');
        $parentId = entity\attribute('parentId');
        $parentType = entity\attribute('parentType');
        $post = entity\attribute('post');
        
        $usernameCatch = string\match($post, '/@\S*/');
        $username = string\substring($usernameCatch, 1);
        $usernameId = record\findOne('User', 'createdAt', 'desc', 'userName=', $username);
        $userTeam = record\attribute('User', $usernameId, 'teamsIds');
        
        record\relate($parentType, $parentId, 'teams', $userTeam);
        
        ifThenElse(
        record\count('Note', 'type=', 'Post', 'parentId=', $parentId, 'post=', $post, 'parentType=', $parentType) == 1,
        record\create('Note', 'type', 'Post', 'post', $post, 'parentType', $parentType, 'parentId', $parentId) && record\update('Note', $noteId, 'deleted', '1')
        );
        Hello,
        This formula works great but only for mentioning one user. For example, if we mention two emma Jack users, only the emma team will be added.
        Has anyone been able to adapt this formula to work for all the mentioned users?​

        Comment


        • #5
          I tried to rewrite the formula myself, but there is an error somewhere. Can anyone see where I made a mistake?
          Code:
          $noteId = entity\attribute('id');
          $parentId = entity\attribute('parentId');
          $parentType = entity\attribute('parentType');
          $post = entity\attribute('post');
          $logins = string\matchAll($post, '/@\S*/');
          
          $listoflogins = list($logins);
          
          
          $i = 0;
          
          while(
              $i < array\length($listoflogins),
              (  
                  $z = array\at($listoflogins, $i)
                  $username = string\substring($z, 1);
                  $usernameId = record\findOne('User', 'createdAt', 'desc', 'userName=', $username);
                  $userTeam = record\attribute('User', $usernameId, 'teamsIds');
                  record\relate($parentType, $parentId, 'teams', $userTeam);
          
                  $i = $i + 1;
              )
          );​

          Comment


          • item
            item commented
            Editing a comment
            Hi,
            Maybe
            matchAll return array

            So no need : $listoflogins = list($logins);
            And adapt all $listoflogins to $logins

        • #6
          Originally posted by ShulzR View Post
          I tried to rewrite the formula myself, but there is an error somewhere. Can anyone see where I made a mistake?
          Code:
          $noteId = entity\attribute('id');
          $parentId = entity\attribute('parentId');
          $parentType = entity\attribute('parentType');
          $post = entity\attribute('post');
          $logins = string\matchAll($post, '/@\S*/');
          
          $listoflogins = list($logins);
          
          
          $i = 0;
          
          while(
          $i < array\length($listoflogins),
          (
          $z = array\at($listoflogins, $i)
          $username = string\substring($z, 1);
          $usernameId = record\findOne('User', 'createdAt', 'desc', 'userName=', $username);
          $userTeam = record\attribute('User', $usernameId, 'teamsIds');
          record\relate($parentType, $parentId, 'teams', $userTeam);
          
          $i = $i + 1;
          )
          );​
          Thanks item there was a mistake! And one more ";" was missing The working formula looks like this:​
          Code:
          $noteId = entity\attribute('id');
          $parentId = entity\attribute('parentId');
          $parentType = entity\attribute('parentType');
          $post = entity\attribute('post');
          $logins = string\matchAll($post, '/@\S*/');
          
          
          
          $i = 0;
          
          while(
              $i < array\length($logins),
              (  
                  $z = array\at($logins, $i);
                  $username = string\substring($z, 1);
                  $usernameId = record\findOne('User', 'createdAt', 'desc', 'userName=', $username);
                  $userTeam = record\attribute('User', $usernameId, 'teamsIds');
                  record\relate($parentType, $parentId, 'teams', $userTeam);
          
                  $i = $i + 1;
              )
          );​
          
          ​

          Comment


          • item
            item commented
            Editing a comment
            thank you for feedback and give a working solution for others.

        • #7
          item lazovic Does anyone know why enabling this workflow causes notifications to be sent twice to the mentioned person?
          Last edited by ShulzR; 12-16-2022, 09:00 AM.

          Comment


        • #8
          item They are two identical messages. Only in 'mentions' I have this message content:
          Attached Files

          Comment


          • #9
            yuri can you help? What can cause that the inclusion of the following workflow results in sending notifications about the mention twice instead of once?​

            Code:
            $noteId = entity\attribute('id');
            $parentId = entity\attribute('parentId');
            $parentType = entity\attribute('parentType');
            $post = entity\attribute('post');
            $logins = string\matchAll($post, '/@\S*/');
            
            
            
            $i = 0;
            
            while(
            $i < array\length($logins),
            (
            $z = array\at($logins, $i);
            $username = string\substring($z, 1);
            $usernameId = record\findOne('User', 'createdAt', 'desc', 'userName=', $username);
            $userTeam = record\attribute('User', $usernameId, 'teamsIds');
            record\relate($parentType, $parentId, 'teams', $userTeam);
            
            $i = $i + 1;
            )
            );​
            ​

            Comment

            Working...
            X