Update all Posts in Stream to a text field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Danny
    Member
    • Aug 2021
    • 35

    Update all Posts in Stream to a text field

    Hi,

    As titled, I am looking for a way to automatically copy all User Posts in Stream to a text field (Description).

    For example,

    - Agent A posted 'abc' in Stream > Description = "Agent A posted abc on dd/mm/yyyy"
    - Next day, Agent B posted 'xyz' in Stream > Description = " Agent B posted xyz on dd/mm/yyyy
    Agent A posted abc on dd/mm/yyyy"
    - And so on,

    Appreciate your helps and suggestions on how it can be done.
  • Kharg
    Senior Member
    • Jun 2021
    • 410

    #2
    Hi,
    if you are interested I have something like this made with hooks and advanced pack and it's like this:

    Code:
    Agent A 08/08/22 10:00
    abc
    
    Agent B 09/08/22 11:00
    xyz

    Comment


    • Danny
      Danny commented
      Editing a comment
      Hi Kharg,

      Thanks for your response. I would love to know more about your work.
  • Kharg
    Senior Member
    • Jun 2021
    • 410

    #3
    So it's made of 3 text fields:

    "ultimaNota", "ultimaNota1" and "storico", so the field "storico" will contain all the stream history.

    and a Hook that you will have to adapt to your entity and to the names of your fields.:
    Storico.php
    Code:
    <?php
    namespace Espo\Custom\Hooks\Lead;
    use Espo\ORM\Entity;
    
    class Storico extends \Espo\Core\Hooks\Base
    {
        public function beforeSave(Entity $entity)
        {
    $ultimanota1 = $entity->get('ultimaNota1');
    $ultimanota = $entity->get('ultimaNota');
    if($ultimanota1 != $ultimanota) {
    $storico = $entity->get('storico');
    $storico .= '
    
    ';
    $storico .= $ultimanota;
    $entity->set('storico', $storico);
    $entity->set('ultimaNota1', $ultimanota);
    }
    }
    }
    ?>
    and then you have to create 2 workflow
    After Record Update and After Record Create
    both with the Note entity
    Conditions:
    Type = Post
    or
    Type = EmailSent
    Execute Formula Script
    Code:
    $user = entity\attribute('createdByName');
    Update related records » Parent » YourEntity
    Field: Post
    Formula: (Edit with your timezone)
    Code:
    ultimaNota = string\concatenate($user, " ",datetime\format(datetime\now(), 'Europe/Amsterdam', 'DD/MM/YYYY HH:mm'),'\n',ultimaNota);
    probably it could be made with just a hook and no advanced pack, but this works fine for my use case.
    Let me know if it works for you!
    Last edited by Kharg; 08-10-2022, 08:02 AM.

    Comment

    Working...