Announcement

Collapse
No announcement yet.

Need Help with Posting Attachments and Text to Note Section via Workflow

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

  • Need Help with Posting Attachments and Text to Note Section via Workflow

    Hello team,

    I have attempted to create a workflow that posts text and attachments to a stream (note). To accomplish this, I created an additional field called "multiple attachment" in the Document entity. Furthermore, I set up a workflow that is meant to post text along with attachments from the "multiple attachment" field to the note section.

    Despite configuring everything as intended, I have been unable to achieve the desired outcome. It seems that I might have overlooked something. Could someone please assist me?

    I have attached an image below displaying the configuration of the workflow.

    Result : When I execute the workflow, no stream records are created. There are no text records or attachments generated as a result.

    I would greatly appreciate any advice or assistance in resolving this issue.
    rabii Can you please Help me on this ?


    Click image for larger version  Name:	image.png Views:	8 Size:	145.3 KB ID:	92647
    Last edited by sapyantuk; 05-19-2023, 09:02 AM.

  • #2
    Have you managed to have the note created but didn’t manage to have the attachments on the created note?
    CEO of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment


    • #3
      what is the i assume the workflow target entity is document right ? did you set the workflow triger type to (after record update)?

      I am not sure what you want to achieve here, you already have the stream available (you just need to enable the stream for the document entity) and then you an post to the stream instead of creating additional field on document. On that note if the stream is disabled for the document entity then the workflow will not work for sure, you have to enable the stream for the document entity.

      I have recreated the same workflow with same data and this code work, don't use both fields and formula when you create a field it cause a conflict in the system, because both do the same thing, instead use just formula like below and it should work fine:

      NB: THIS CODE WORKS HOWEVER WHEN CREATES THE NEW POST IT DOES LINK THE ATTACHMENTS TO THE POST AND THEY ARE AUTOMATICALLY UNLINKED FROM THE DOCUMENT ENTITY. IF YOU WISH TO KEEP ATTACHMENTS ON BOTH DOCUMENT AND POST (NOTE) THEN YOU USE THE SECOND CODE BELOW:



      // This code link the attachments to the note entity and unlink them from the document entity
      PHP Code:
      attachmentsIds workflow\targetEntity\attribute('attachmentsIds');
      post 'Old file has been updated with a new one';
      type 'Post';
      parentType 'Document';
      parentId workflow\targetEntity\attribute('id');
      createdById workflow\targetEntity\attribute('modifiedById'); 


      // This code loop through the Document's attachments and then create similar files to keep the ones on document and attach new created ones to the note entity
      PHP Code:
      $source workflow\targetEntity\attribute('attachmentsIds');
      $newAttachments = list();

      $i 0;

      while(
          
      $i array\length($source),
          (
              
      $newAttachments array\push(
                  
      $newAttachments,
                  
      record\create('Attachment',
                      
      'role''Attachment',
                      
      'type'record\attribute('Attachment'array\at($source$i), 'type'),
                      
      'size'record\attribute('Attachment'array\at($source$i), 'size'),
                      
      'global'record\attribute('Attachment'array\at($source$i), 'global'),
                      
      'name'record\attribute('Attachment'array\at($source$i), 'name'),
                      
      'sourceId'$fileId,
                      
      'storage'record\attribute('Attachment'array\at(documentAttachments$i), 'storage'),
                      
      'field''attachments',
                      
      'parentType''Note'
                  
      )
              );
              
              
      $i $i 1;
          )
      );

      attachmentsIds $newAttachments;
      post 'Howdy Old file has been updated with a new one!';
      type 'Post';
      parentType 'Document';
      parentId workflow\targetEntity\attribute('id');
      createdById workflow\targetEntity\attribute('modifiedById'); 


      I have tested both codes and they work as expected please remember to enable stream for document entity in order for the workflow to work.

      YOU CAN ONLY USE ONE OF THE CODES ABOVE NOT BOTH, IF YOU WISH TO KEEP ATTCHMENTS ON DOCUMENTS AND ALSO HAVE SAME ATTACHMENTS ON THE NOTE ENTITY IN TEH STREAM THEN USE THE SECOND CODE.

      hope this helps.
      Rabii
      Web Dev

      Comment


      • #4
        rabii

        I want to mention that I have already enabled the stream feature in the document entity. Despite this, I have tried two different code implementations, but neither of them is producing any desired results.

        I would greatly appreciate any assistance or guidance you can provide in resolving this matter. Please let me know if there is any additional information or context I can provide to help you better understand the situation.

        Thank you for your attention to this matter.

        Comment


        • rabii
          rabii commented
          Editing a comment
          i am sure that the code works, can you share the workflow trigger type and also try to adda condition to the workflow e.g attachments changed or so. if you can share more details i can figure out why not working.

      • #5
        rabii Please check

        Click image for larger version

Name:	image.png
Views:	285
Size:	38.9 KB
ID:	92665​​
        Attached Files

        Comment


        • rabii
          rabii commented
          Editing a comment
          instead of condition attachments changed make it attachment not empty. changed won't work

      • #6
        what is the name of the multiple attachments field you added on the document entity ? can you check that for me please

        also see a video here which show how it works with same params:

        Rabii
        Web Dev

        Comment


        • #7
          Click image for larger version

Name:	image.png
Views:	291
Size:	47.8 KB
ID:	92670
          Click image for larger version

Name:	image.png
Views:	269
Size:	23.0 KB
ID:	92671

          rabii Please check​​

          Comment


          • #8
            rabii Text are creating in stream but there is no any attachment posted in stream

            Click image for larger version

Name:	image.png
Views:	318
Size:	23.8 KB
ID:	92675

            Comment


            • #9
              did you upload any files to the document (multiple attachment field) on the document ?
              Rabii
              Web Dev

              Comment


              • #10
                Can you please connect on teamviewer for 5 minutes

                Comment


                • #11
                  pass your team id so i could log into your session
                  Rabii
                  Web Dev

                  Comment


                  • #12
                    822 816 264

                    zweu1w82

                    Comment


                    • #13
                      Hi sapyantuk,

                      Replace the crossed-out formula in your Action > Create Record » Note (as shown in the screenshot) and insert the following formula:
                      Code:
                      $attachmentsIds = workflow\targetEntity\attribute('documentIds');
                      
                      $i = 0;
                      
                      $documentIds = list();
                      
                      while(
                          
                          $i < array\length($attachmentsIds),
                          $attachmentId = array\at($attachmentsIds, $i);
                      
                          $documentId = record\create('Attachment',
                          'role', 'Attachment',
                          'type', record\attribute('Attachment', $attachmentId, 'type'),
                          'size', record\attribute('Attachment', $attachmentId, 'size'),
                          'global', record\attribute('Attachment', $attachmentId, 'global'),
                          'name', record\attribute('Attachment', $attachmentId, 'name'),
                          'sourceId', $attachmentId,
                          'storage', record\attribute('Attachment', $attachmentId, 'storage'),
                          'parentName', targetEntity\attribute('name'),
                          'parentId', targetEntity\attribute('id'),
                          'parentType', 'Note',
                          'field', 'attachments'
                      );
                              
                          $documentIds = array\push($documentIds, $documentId);
                              
                          entity\addLinkMultipleId(
                              'attachments', $documentIds
                          );
                      
                          $i = $i + 1;
                          
                      );
                      
                      post = 'Howdy Old file has been updated with a new one!';
                      type = 'Post';
                      parentType = 'Document';
                      parentId = workflow\targetEntity\attribute('id');
                      createdById = workflow\targetEntity\attribute('modifiedById');​
                      Attached Files
                      Last edited by victor; 05-19-2023, 02:43 PM.

                      Comment


                      • #14
                        rabii when i change the documents . note is creating in stream section but when i open the attachment from note section . attachment is not opening

                        Click image for larger version

Name:	image.png
Views:	275
Size:	51.6 KB
ID:	93588

                        Click image for larger version

Name:	image.png
Views:	231
Size:	18.2 KB
ID:	93589victor

                        Comment


                        • rabii
                          rabii commented
                          Editing a comment
                          it seems that the file is not persisted in the storage folder. can you share the code we have used last time ? i need to review that

                        • sapyantuk
                          sapyantuk commented
                          Editing a comment
                          // now let try and see if this will work - if it doesn't it will confirm that the issue is with the workflow
                          $documentIds = workflow\targetEntity\attribute('documentIds');
                          $newAttachments = list();
                          $i = 0;

                          while(
                          $i < array\length($documentIds),
                          (
                          $newAttachments = array\push(
                          $newAttachments,
                          record\create('Attachment',
                          'role', 'Attachment',
                          'type', record\attribute('Attachment', array\at($documentIds, $i), 'type'),
                          'size', record\attribute('Attachment', array\at($documentIds, $i), 'size'),
                          'global', record\attribute('Attachment', array\at($documentIds, $i), 'global'),
                          'name', record\attribute('Attachment', array\at($documentIds, $i), 'name'),
                          'sourceId', $fileId,
                          'storage', record\attribute('Attachment', array\at($documentIds, $i), 'storage'),
                          'field', 'attachments',
                          'parentType', 'Note'
                          )
                          );

                          $i = $i + 1;
                          )
                          );

                          record\create('Note',
                          'post', 'Howdy Old file has been updated with a new one!',
                          'attachmentsIds', $newAttachments,
                          'type', 'Post',
                          'parentType', 'Document',
                          'parentId', workflow\targetEntity\attribute('id'),
                          'createdById', modifiedById
                          );

                        • rabii
                          rabii commented
                          Editing a comment
                          Yap this is what cause the issue ('sourceId', $fileId,) . it had to be 'sourceId', record\attribute('Attachment', array\at($documentIds, $i), 'id') instead

                      • #15
                        sapyantuk,

                        Checked in two test instances, everything works as it should. And the files created in Stream are available for viewing and downloading.

                        Click image for larger version

Name:	1.png
Views:	258
Size:	32.0 KB
ID:	93598
                        Click image for larger version

Name:	2.png
Views:	217
Size:	50.9 KB
ID:	93599
                        Click image for larger version

Name:	3.png
Views:	229
Size:	42.1 KB
ID:	93600

                        Comment

                        Working...
                        X