Reference stream posts & status changes in PDF templates?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • migrator
    Member
    • Apr 2023
    • 38

    Reference stream posts & status changes in PDF templates?

    Hello all!

    I really want to include all the non-internal Posts and Status Changes in the PDF for Cases somehow.

    Tried to rtfm this extensively, but have not seen any mention of how to reference the Stream ( Posts and Status Changes ) in a PDF template -- for example in Cases.

    Tried this also to see if it was in scope, like so, but I see no objects to grab and iterate through:

    Code:
    {{#each this}}
    {{@key}} – key
    {{/each}}
    Also looked a the Entity Relationships available to Cases, and see nothing, except Notes, but that seems to be a different entity than Stream Posts.

    Also looked through the Issues on GitHub for clues.

    I am extremely new to EspoCRM, and would appreciate the help of a veteran! Possibly an easy question.

    Thank you very much!
  • lazovic
    Super Moderator
    • Jan 2022
    • 809

    #2
    Hi migrator,

    This functionality can be done using Workflow (Advanced Pack extension feature):
    1. Go to Administration > API Users and create an API User and select a Role with maximum access for it (you can create Role in Administration > Roles).
    2. Copy its API key.
    3. Create in all entities, for which it will be necessary to pull out all posts in PDF Templates, the Text field with the Text type (go to Administration > Entity Manager > your entities > Fields and create a new field).
    4. Go to Administration > Workflows and create the following Workflow:

      Click image for larger version  Name:	image.png Views:	0 Size:	39.3 KB ID:	90772
      With the following Actions:

      Click image for larger version  Name:	image.png Views:	0 Size:	23.1 KB ID:	90773

      Click image for larger version  Name:	image.png Views:	0 Size:	56.4 KB ID:	90774​​

      In Send HTTP Request Action, instead of http://localhost/espo-master, insert the URL of your EspoCRM instance. Paste the previously copied API Key into the Headers (from point 2).

      FULL formula for Execute Formula Script Action:

      Code:
      	$parentId = workflow\targetEntity\attribute('parentId');
      	$parentType = workflow\targetEntity\attribute('parentType');
      
      	$getResponce = json\retrieve($_lastHttpResponseBody, 'list');
      	$getResponceEncode = json\encode($getResponce);
      
      	// USERS
      	$i = 0;
      	$usersArray = list();
      
      	while(
      	$i < array\length($getResponce),
      	(
      	$usersArray = array\push($usersArray, json\retrieve($getResponceEncode, string\concatenate('', $i, '.createdByName'))
      	);
      
      	$i = $i + 1;
      
      	)
      	);
      
      	// POSTS
      	$i = 0;
      	$postsArray = list();
      
      	while(
      	$i < array\length($getResponce),
      	(
      	$postsArray = array\push($postsArray, json\retrieve($getResponceEncode, string\concatenate('', $i, '.post'));
      	);
      
      	$i = $i + 1;
      
      	)
      	);
      
      	// DATETIME
      	$i = 0;
      	$createdAtArray = list();
      
      	while(
      	$i < array\length($getResponce),
      	(
      	$createdAtArray = array\push($createdAtArray, json\retrieve($getResponceEncode, string\concatenate('', $i, '.createdAt'))
      	);
      
      	$i = $i + 1;
      
      	)
      	);
      
      	// GENERAL
      	$i = 0;
      	$concatenateUsersAndPosts = list();
      	$pushDataToArray = list();
      	$text = list();
      
      	while(
      	$i < array\length($getResponce),
      	(
      	$concatenateUsersAndPosts = string\concatenate(array\at($usersArray, $i), ' posts ', array\at($postsArray, $i), ' at ', array\at($createdAtArray, $i));
      	$pushDataToArray = array\push($pushDataToArray, $concatenateUsersAndPosts);
      	$text = array\join($pushDataToArray, '\n\n');
      	);
      
      	$i = $i + 1;
      
      	);
      
      	record\update($parentType, $parentId, 'text', $text);​
    5. For PDF Templates of the desired entity types, insert a Text placeholder into the body, in which information about posts will be displayed in the following format:
      Admin posts Text at 2023-04-11 13:09:14

      Admin posts Text 1 at 2023-04-11 13:05:23

      Admin posts Text 2 at 2023-04-11 13:01:11
    This workflow can be modified in many ways, and so far it only works for posts of the Post type. That is, it cannot get information about changing the Status, but this can be corrected and supplemented, just let me know.​
    Last edited by lazovic; 04-11-2023, 01:50 PM.

    Comment


    • migrator
      migrator commented
      Editing a comment
      Wow @iazovic! Thank you so much for the in-depth and highly detailed answer! I will go through this at great length several times, then prepare to go this direction. What an extremely complete answer.
Working...