Use formula to insert file from Documents to a field of type File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iceman17
    Junior Member
    • Sep 2017
    • 15

    Use formula to insert file from Documents to a field of type File

    How can I use formula to insert a file already in Documents?

    Click image for larger version

Name:	image.png
Views:	97
Size:	7.6 KB
ID:	106816
    Attached Files
  • lazovic
    Super Moderator
    • Jan 2022
    • 810

    #2
    Hi iceman17,

    You can use the following formula script:
    Code:
    $documentId = '66276bba76b9d6749'; // define the ID of the document that will be entered in the File field
    
    $documentFileId = record\attribute('Document', $documentId, 'fileId');
    
    fileId = record\create('Attachment',
                           'name', record\attribute('Attachment', $documentFileId, 'name'),
                           'type', record\attribute('Attachment', $documentFileId, 'type'),
                           'size', record\attribute('Attachment', $documentFileId, 'size'),
                           'field', record\attribute('Attachment', $documentFileId, 'field'),
                           'role', record\attribute('Attachment', $documentFileId, 'role'),
                           'storage', record\attribute('Attachment', $documentFileId, 'storage'),
                           'global', record\attribute('Attachment', $documentFileId, 'global'),
                           'relatedId', id,
                           'relatedName', name,
                           'relatedType', 'CTest', // insert your entity name (where the File field is presented)
                           'sourceId', $documentFileId
                           );

    Comment

    Working...