Extracting the name of attachments from email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LuckyLouie
    Senior Member
    • Nov 2017
    • 172

    Extracting the name of attachments from email

    Hello,
    I need to extract the names of attachments from an email.
    The attachmentIds extraction is working fine:
    HTML Code:
    $list = record\attribute('Email', '65fd41542cce03aba', 'attachmentsIds');
    where am I going wrong in extracting the names?​
    HTML Code:
    $list = record\attribute('Email', '65fd41542cce03aba', 'attachmentsNames');
    Thanks
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    attachmentsNames is a a not storable field. you would have to loop through the attachments and get the name of each one of them as below

    PHP Code:
    $ids = record\attribute('Email', '65fd41542cce03aba', 'attachmentsIds');
    
    $names = list();
    
    $i = 0;
    
    while($i < array\length($ids)){
        
        $o = record\fetch('Attachment', array\at($ids, $i));
        
        if ($o) {
            $name = object\get($o, 'name');
            $names = array\push($names, $name);
        }
    
        $i = $i + 1;
    }
    
    $names = array\join($names, ' - ');​​ 
    
    Rabii
    Web Dev

    Comment

    • LuckyLouie
      Senior Member
      • Nov 2017
      • 172

      #3
      Thank you rabii.
      However, I have a little problem. I don't know why your formula works in sandbox, but when I try to use it in bpm or workflow it doesn't work:
      Click image for larger version

Name:	invoice.jpg
Views:	113
Size:	92.5 KB
ID:	104026
      I am sending an attachment called Invoice, but the process goes through the right side :/

      Comment


      • rabii
        rabii commented
        Editing a comment
        Can you share more details maybe some code is blocking the execution.
    • LuckyLouie
      Senior Member
      • Nov 2017
      • 172

      #4
      I don't know why the $names variable in workflow or bpm always returns an empty value even though the same script in the sandbox returns the correct value.
      For example, below is the workflow which also does not work, and when testing the same script, it returns 'true' on the same email in the sandbox​:
      Click image for larger version

Name:	1.jpg
Views:	103
Size:	74.2 KB
ID:	104075

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #5
        Hey,

        I have noticed that you are using trigger type => After record saved (This will always trigger on update as default) i would suggest to change that to After record created which will be triggered only when the parent is opportunity. i have tested this and it works on a bpmn - on workflow won't work as the formula condition will always return null while it should return a boolean. I suggest that you use bpmn. please find attached a flowchart you can import and test with it and also build on it.

        I hope this helps
        Attached Files
        Rabii
        Web Dev

        Comment

        Working...