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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #16
    i think it was an issue in the code (just checked the code again and it was an issue with sourceId). sapyantuk you need to update the code, the code provided by victor should work fine.
    Rabii
    Web Dev

    Comment

    • sapyantuk
      Senior Member
      • Oct 2020
      • 265

      #17
      rabii
      here is the code


      // 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
      );​

      Comment

      • victor
        Active Community Member
        • Aug 2022
        • 727

        #18
        I pasted your code and got the same error as you. You should use this code:
        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');​

        Comment

        • sapyantuk
          Senior Member
          • Oct 2020
          • 265

          #19
          victor

          after pasting the code you have provided . no any result or no any record has created in note section

          Click image for larger version

Name:	image.png
Views:	105
Size:	54.5 KB
ID:	93616

          Comment


          • victor
            victor commented
            Editing a comment
            When I inserted your code into the Action of my workflow, I got the same error as you. Then pasted the code from my previous post and it worked. I sent you the video proof privately.

          • sapyantuk
            sapyantuk commented
            Editing a comment
            Thank you so much . everthing works fine for now
        • sapyantuk
          Senior Member
          • Oct 2020
          • 265

          #20
          Problem solved . Thanks to the Devloper victor rabii

          Comment

          Working...