<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Use code in workflow to copy first &amp;amp; lastname from email adress in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/875330#M68830</link>
    <description>&lt;P&gt;Hello fellow HubsSpotters!&lt;BR /&gt;&lt;BR /&gt;We have an issue with not having First and Last name values in our CRM (lazy sales reps etc). However many email-values of our prospects contains their first and last name. Eg &lt;A href="mailto:First_name.Last_name@companydomain.com" target="_blank"&gt;First_name.Last_name@companydomain.com&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I therefore wonder if there is a way to use the custom code function in workflows, or something of the like...&lt;BR /&gt;&lt;BR /&gt;If there is, maybe I can use workflows to:&lt;BR /&gt;&lt;STRONG&gt;identify an email adresses that has a "value1" separated by a dot to "value2".&lt;/STRONG&gt; eg Value1.Value2@email.com &lt;BR /&gt;&lt;BR /&gt;and then get Hubspot to:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Copy value1 to First name&lt;/STRONG&gt;&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;Copy value2 to Last name&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;I understnad that this solution wont be perfect based on the email adress, but its better than leaving them blank. Maybe there is a way to not copuy values les than two characters etc to avoid naming people a single letter, or exclude numbers or something. All ideas would be much appreciated. Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Nov 2023 15:30:13 GMT</pubDate>
    <dc:creator>AxelS</dc:creator>
    <dc:date>2023-11-06T15:30:13Z</dc:date>
    <item>
      <title>Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/875330#M68830</link>
      <description>&lt;P&gt;Hello fellow HubsSpotters!&lt;BR /&gt;&lt;BR /&gt;We have an issue with not having First and Last name values in our CRM (lazy sales reps etc). However many email-values of our prospects contains their first and last name. Eg &lt;A href="mailto:First_name.Last_name@companydomain.com" target="_blank"&gt;First_name.Last_name@companydomain.com&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I therefore wonder if there is a way to use the custom code function in workflows, or something of the like...&lt;BR /&gt;&lt;BR /&gt;If there is, maybe I can use workflows to:&lt;BR /&gt;&lt;STRONG&gt;identify an email adresses that has a "value1" separated by a dot to "value2".&lt;/STRONG&gt; eg Value1.Value2@email.com &lt;BR /&gt;&lt;BR /&gt;and then get Hubspot to:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Copy value1 to First name&lt;/STRONG&gt;&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;Copy value2 to Last name&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;I understnad that this solution wont be perfect based on the email adress, but its better than leaving them blank. Maybe there is a way to not copuy values les than two characters etc to avoid naming people a single letter, or exclude numbers or something. All ideas would be much appreciated. Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2023 15:30:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/875330#M68830</guid>
      <dc:creator>AxelS</dc:creator>
      <dc:date>2023-11-06T15:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/876138#M68884</link>
      <description>&lt;P&gt;Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91547"&gt;@AxelS&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Happy to brainstorm with you. I think you are on the right path with using a Custom Coded Workflow Action. I don't have a full custom coded example for you. And let's list out the parts, assuming JavaScript is your tool of choice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what come to my mind:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Extract the email address&lt;/LI&gt;
&lt;LI&gt;Use Regex to find the first and last names separated by a dot&lt;/LI&gt;
&lt;LI&gt;Capitalize the first letter of the extracted names&lt;/LI&gt;
&lt;LI&gt;Run a check to ignore single-letter names or numeric values&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Outputs your shiny new first and last names to be used in the rest of your workflow&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Regular expressions always make my head hurt. You might consider this one:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// Regular expression to match email in the format of first.last@example.com
const namePattern = /^([a-zA-Z]+)\.([a-zA-Z]+)@/;
const match = email.match(namePattern);
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While the community likely cannot provide complete custom code for you, sharing your code and any errors you get back, gives them something specific to help troubleshoot.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have fun building! — Jaycee&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 18:20:14 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/876138#M68884</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-11-07T18:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/876409#M68903</link>
      <description>&lt;P&gt;Thank you for setting me on the right path.&lt;BR /&gt;&lt;BR /&gt;I have (with the help of a developer and some ChatGPT) tried this code. I don't get any errors, but the first and last name does not populate on my contact. Since I don't have any errors in the code I was wondering if I need to ad som extra steps in my workflow? Right now I just have the enrollment trigger and then the code action.&lt;BR /&gt;&lt;BR /&gt;Thanks for any help in this mystery!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt;exports.main = async (event, callback) =&amp;gt; {
  const email = event.inputFields['email'];

  if (email &amp;amp;&amp;amp; typeof email === 'string') {
    const namePattern = /^([a-zA-Z]+)\.([a-zA-Z]+)@/;
    const match = email.match(namePattern);

    if (match) {
      const firstname = match[1];
      const lastname = match[2];

      callback({
        outputFields: {
          email: email,
          firstname: firstname,
          lastname: lastname
        }
      });
    }
  }
};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AxelS_0-1699429940149.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/102824iAC1022CEA23AE03E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AxelS_0-1699429940149.png" alt="AxelS_0-1699429940149.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 07:56:38 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/876409#M68903</guid>
      <dc:creator>AxelS</dc:creator>
      <dc:date>2023-11-08T07:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/966374#M73105</link>
      <description>&lt;P&gt;This worked a treat.. thanks for sharing.&lt;/P&gt;&lt;P&gt;The workflow was setup like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SMoyse_0-1714021845136.png" style="width: 999px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/116116i6665C9CB2F55930D/image-size/large?v=v2&amp;amp;px=999" role="button" title="SMoyse_0-1714021845136.png" alt="SMoyse_0-1714021845136.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;With email being input&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SMoyse_1-1714021875672.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/116117i04749D4E34B542CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SMoyse_1-1714021875672.png" alt="SMoyse_1-1714021875672.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;exports.main = async (event, callback) =&amp;gt; {
  /*****
    Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
  *****/
  const email = event.inputFields['email'];
  let firstname;
  let lastname;
  let emailMatch;
  
  if (email &amp;amp;&amp;amp; typeof email === 'string') {
    const namePattern = /^([a-zA-Z]+)\.([a-zA-Z]+)@/;
    const match = email.match(namePattern);

    if (match) {
      firstname = match[1].charAt(0).toUpperCase() + match[1].slice(1); //Setting and formating first letter to upper case
      lastname = match[2].charAt(0).toUpperCase() + match[2].slice(1); //Setting and formating first letter to upper case
      emailMatch = true;
    } else{
      emailMatch = false;
      console.log(`Email match is ${emailMatch}`)
      //throw new Error("Email doesn't match pattern");
    }
  }
  
  /*****
    Use the callback function to output data that can be used in later actions in your workflow.
  *****/
  callback({
    outputFields: {
      firstname: firstname,
      lastname: lastname,
      emailMatch: emailMatch
    }
  });
}&lt;/LI-CODE&gt;&lt;P&gt;Outputs as:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SMoyse_2-1714021975330.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/116118i7973F8D42BD53F90/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SMoyse_2-1714021975330.png" alt="SMoyse_2-1714021975330.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 05:13:17 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/966374#M73105</guid>
      <dc:creator>sMoyse</dc:creator>
      <dc:date>2024-04-25T05:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/967229#M73158</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/525436"&gt;@sMoyse&lt;/a&gt;&amp;nbsp;, this looks perfect!&lt;BR /&gt;could you show in more detail how you did the branching and set properties parts as I can't work out how you've done those parts &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 11:32:00 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/967229#M73158</guid>
      <dc:creator>PArd</dc:creator>
      <dc:date>2024-04-26T11:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/1038312#M76464</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91547"&gt;@AxelS&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I stumbled onto a similar case a few weeks ago. If you want a solution more generic, we used an LLM, integrated into a Hubspot Custom Code and it gave spectacular results&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;It handles easily &lt;A href="mailto:first.last@domain.com," target="_blank" rel="noopener"&gt;first.last@domain.com,&lt;/A&gt;&amp;nbsp;&lt;A href="mailto:first@last.com," target="_blank" rel="noopener"&gt;first@last.com,&lt;/A&gt;&amp;nbsp;&lt;A href="mailto:first.last.012@gmail.com," target="_blank" rel="noopener"&gt;first.last.012@gmail.com,&lt;/A&gt;&amp;nbsp;&lt;A href="mailto:first-last@yahoo.com" target="_blank" rel="noopener"&gt;first-last@yahoo.com,&lt;/A&gt;&amp;nbsp;it guesses most of time which one is (likely) the first name, the last name, with a really large set of languages.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Let's get in touch if needed!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 12:10:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/1038312#M76464</guid>
      <dc:creator>Xavier-Plum</dc:creator>
      <dc:date>2024-09-09T12:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/1071986#M78376</link>
      <description>&lt;P&gt;This is really helpful, im just struggling with how you did the branching as i cant find how you set these up either&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 22:44:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/1071986#M78376</guid>
      <dc:creator>DDavis37</dc:creator>
      <dc:date>2024-11-19T22:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use code in workflow to copy first &amp; lastname from email adress</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/1083170#M78939</link>
      <description>&lt;P&gt;Wrote this python code instead. Takes in email and gives you first name, last name, and number of names (0, 1, 2). Branch if count is 1 or 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;def main(event):&lt;BR /&gt;"""&lt;BR /&gt;Extract firstname and lastname from email, and calculate namecounts. &lt;BR /&gt;Returns:&lt;BR /&gt;dict: A dictionary with extracted 'firstname', 'lastname', and 'namecounts'.&lt;BR /&gt;"""&lt;BR /&gt;email = event.get("inputFields", {}).get("email", "")&lt;BR /&gt;firstname = None&lt;BR /&gt;lastname = None&lt;BR /&gt;namecounts = 0&lt;BR /&gt;&lt;BR /&gt;if email and isinstance(email, str):&lt;BR /&gt;# Split the email into local and domain parts&lt;BR /&gt;local_part = email.split("@")[0]&lt;BR /&gt;parts = local_part.split(".")&lt;BR /&gt;&lt;BR /&gt;# Extract firstname and lastname&lt;BR /&gt;if len(parts) &amp;gt; 0 and parts[0]:&lt;BR /&gt;firstname = parts[0].capitalize()&lt;BR /&gt;namecounts += 1&lt;BR /&gt;&lt;BR /&gt;if len(parts) &amp;gt; 1 and parts[1]:&lt;BR /&gt;lastname = parts[1].capitalize()&lt;BR /&gt;namecounts += 1&lt;BR /&gt;&lt;BR /&gt;return {&lt;BR /&gt;"outputFields": {&lt;BR /&gt;"firstname": firstname,&lt;BR /&gt;"lastname": lastname,&lt;BR /&gt;"namecounts": namecounts&lt;BR /&gt;}&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 12:07:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Use-code-in-workflow-to-copy-first-amp-lastname-from-email/m-p/1083170#M78939</guid>
      <dc:creator>Userpilot_One</dc:creator>
      <dc:date>2024-12-13T12:07:03Z</dc:date>
    </item>
  </channel>
</rss>

