Announcement

Collapse
No announcement yet.

Get and map values from email

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

  • Get and map values from email

    Is there any way to fetch a string / value from a incoming email?

    Today I create a contact with name and emailAddress for every email that arrives. All emails arriving are sent from a stativ form and contains phone number, address etc.

    So ideally I would like to get the values for each and add it to the contact. A message would usually look something like this:
    Phone: 12345678
    Address: Examplestreet 4076
    Country: Examplecountry
    Subject: somesubject
    Message: some message

    I'm using the BPM flowchart now. But if needed I could use a workflow as well.
    Last edited by hrdy90; 03-07-2023, 05:42 PM.

  • #2
    This example extracts phone and address. Try running in the Formula Sandbox.

    Code:
    $message = "
        Phone: 12345678
        Address: Examplestreet 4076
        Country: Examplecountry
        Subject: somesubject
        Message: some message
    ";
    
    // $ - end of line
    // m - multi-line search
    
    $phoneLine = string\match($message, '/Phone\: (.*)$/m');
    $phone = string\substring($phoneLine, 7);
    
    $addressLine = string\match($message, '/Address\: (.*)$/m');
    $address = string\substring($addressLine, 9);
    
    output\printLine(string\concatenate('Phone: ', $phone));
    output\printLine(string\concatenate('Address: ', $address));​
    Last edited by yuri; 03-07-2023, 06:05 PM.

    Comment


    • #3
      string\match formula maybe?


      Edit: Yuri was faster

      Comment


      • #4
        Wow, thank you. Worked perfectly!
        Last edited by hrdy90; 03-07-2023, 09:35 PM. Reason: Found the "body" attribute.

        Comment


        • #5
          I now have that working in the sandbox. Trying to use the fomula in a flowchart:
          Target entity: Email
          Create Record: Contact

          And syntax:
          $message = bodyPlain;

          $phoneLine = string\match($message, '/Telefon:\ (.*)$/m');
          $phone = string\substring($phoneLine, 9);

          $addressLine = string\match($message, '/Gatuadress\: (.*)$/m');
          $address = string\substring($addressLine, 12);

          $streetNumberLine = string\match($message, '/Gatunummer\: (.*)$/m');
          $streetNumber = string\substring($streetNumberLine, 12);

          phoneNumber = $phone;
          addressStreet = $address;

          Does not seem to set neither phoneNumber or addressStreet. Could it be that being inside "Create record contact" does not see the mail body?

          If so, is there some way to pass it down the flowchart and use it later on?

          Edit: Adding a screenshot as well. It does create contact and populate email+name properly as expected.
          Attached Files
          Last edited by hrdy90; 03-07-2023, 10:42 PM. Reason: Adding a screenshot.

          Comment


          • lazovic
            lazovic commented
            Editing a comment
            Please try to change first line to this:
            $message = bpm\targetEntity\attribute('bodyPlain');

          • hrdy90
            hrdy90 commented
            Editing a comment
            That worked. Thank you!

        • #6
          Originally posted by yuri View Post
          This example extracts phone and address. Try running in the Formula Sandbox.

          Code:
          
          
          This is cool... would anyone be able to assist with a "Button" for this to be done manually instead of automatic/require BPM.

          Comment


          • lazovic
            lazovic commented
            Editing a comment
            In the newest version of the Advanced Pack extension, it is possible to create a Workflow that will be triggered by pressing a button (it is created when the Workflow itself is created). You can learn more about this type of Workflow here: https://docs.espocrm.com/administrat...kflows/#manual.

          • esforim
            esforim commented
            Editing a comment
            Thank you lazovic. That a handy tip for those that have the Workflow. And sound like lots of more possibility if your mind is creative.
        Working...
        X