Announcement

Collapse
No announcement yet.

Stream posts in Email and PDF templates

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

  • Stream posts in Email and PDF templates

    Hi,

    we were wondering whether it would be possible to get stream posts in Email/PDF templates? I would imagine it should be possible, similar to how you can add for example items with their attributes from the sales pack using each function <!-- {{#each itemList}} -->​. As I understand stream posts are stored in the "Notes" entity, but we could not figure out how to fetch those posts in the template, maybe someone has done it or knows how it could possibly be done?

  • #2
    Hi Mark,

    Alternatively, you can create a field in the entity, where all users posts from the stream will be written to by workflow (Advanced Pack extension feature). Then you can simply output this field in the PDF Template.

    How it can be done:
    1. In each entity for which you need to output posts from stream, create a field called stream with the Text type.
    2. Create a workflow like in the screenshot (this workflow will work in this case only for Case entity):
    Click image for larger version  Name:	image.png Views:	0 Size:	65.2 KB ID:	99099​​

    Formula script used:
    Code:
    $createdByName = workflow\targetEntity\attribute('createdBy.name');
    $createdAt = workflow\targetEntity\attribute('createdAt');
    $type = workflow\targetEntity\attribute('type');
    
    stream = string\concatenate(stream,
                                '\n',
                                $post,
                                '\n',
                                $createdByName,
                                '\n',
                                $createdAt,
                                '\n');​
    If needed, for every other entity, just add another similar action in this workflow. Before that create a stream field as previously mentioned.​

    If you want to push all users posts to the stream field right now, create the following workflow (still the same example for Case):

    Click image for larger version  Name:	image.png Views:	0 Size:	45.0 KB ID:	99100
    Click image for larger version  Name:	image.png Views:	0 Size:	80.7 KB ID:	99101
    ​​
    Formula script used:
    Code:
    $notesCount = json\retrieve($_lastHttpResponseBody, 'total');
    
    $caseId = workflow\targetEntity\attribute('id');
    $caseStream = workflow\targetEntity\attribute('stream');
    
    $i = 0;
    
    while(
        
        $i < $notesCount,
        
        (
            $noteId = json\retrieve($_lastHttpResponseBody, string\concatenate('list.', $i, '.id'));
            $noteCreatedAt = record\attribute('Note', $noteId, 'createdAt');
            $notePost = record\attribute('Note', $noteId, 'post');
            $noteCreatedByName = record\attribute('Note', $noteId, 'createdBy.name');
            
            $stream = array\push($stream, string\concatenate(
                                '\n',
                                $notePost,
                                '\n',
                                $noteCreatedByName,
                                '\n',
                                $noteCreatedAt,
                                '\n'));
                                        
            $i = $i + 1;
        )
    );
    
    $streamFull = array\join($stream, '\n');
    
    record\update('Case', $caseId, 'stream', string\concatenate($caseStream, '\n', $streamFull));      ​
    So when you click on the Push notes to stream field button in the upper right corner of Case record, all the user posts from Stream will be moved to the stream field.

    Keep in mind that you will need to create an API User and give it a Role with access to Cases (or any other entity where you want to push in field posts from the stream), then copy its API Key and paste it into the Send HTTP Request action. Also, in the same action you need to change the URL of your instance.

    The output of the Stream field in the PDF Template will look like this:

    Click image for larger version

Name:	image.png
Views:	96
Size:	18.9 KB
ID:	99103
    Last edited by lazovic; 10-26-2023, 11:55 AM.

    Comment

    Working...
    X