⚙ Operations Hub

DSwanich8
Participant

Checking for - or ' in a name field

SOLVE

Has any one out there used a custom coded workflow to check for an - or ' in their first name, and to capitalise the first letter proceeding the - or '.

 

We've used the native data format action in a workflow to change all first names and last names to title case. But that's caused issues for the names that contain an - or '.

 

We can't find anything online to help troubleshoot this. Would be amazing if this use case was added to the Programmable Automation Use Cases ppage. 

1 Accepted solution
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Checking for - or ' in a name field

SOLVE

Hi @DSwanich8 ,

 

I think the following code could work:

exports.main = async (event, callback) => {
  // Pass firstname as a property to include in the code
  let firstname = event.inputFields['firstname'];
  
  // This will turn Lily-mae in Lily-Mae
  if (firstname.includes('-')) {
	const parts = firstname.split('-')
    const firstPart = parts[0]
    let secondPart = parts[1]
    secondPart = secondPart.charAt(0).toUpperCase() + secondPart.slice(1);
    
    firstname = firstPart + secondPart
  } 
  
  // This will turn O'neil into O'Neil
  if (firstname.includes("'")) {
    const parts = firstname.split("'")
    const firstPart = parts[0]
    let secondPart = parts[1]
    secondPart = secondPart.charAt(0).toUpperCase() + secondPart.slice(1);
    
    firstname = firstPart + secondPart
  }

  // Define firstname as an output at the bottom to be able to use the 'copy to property action and save the firstname'
  callback({
    outputFields: {
      firstname: firstname,
    }
  });
}

If you set 'firstname' as an output, you can use the copy to property action to store the firstname for this contact. I did not test this tho, so let me know if you run into any issues.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

2 Replies 2
MSaye
Participant

Checking for - or ' in a name field

SOLVE

Hi Teun,

 

I've been looking for a solution like this. I do have a question relating to it. 

 

What would you do for last name suffixes? For example, "Johnson II" 

If they were a junior (Jr) or senior (Sr), that can be changed with your previous code.

 

Thanks!

0 Upvotes
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Checking for - or ' in a name field

SOLVE

Hi @DSwanich8 ,

 

I think the following code could work:

exports.main = async (event, callback) => {
  // Pass firstname as a property to include in the code
  let firstname = event.inputFields['firstname'];
  
  // This will turn Lily-mae in Lily-Mae
  if (firstname.includes('-')) {
	const parts = firstname.split('-')
    const firstPart = parts[0]
    let secondPart = parts[1]
    secondPart = secondPart.charAt(0).toUpperCase() + secondPart.slice(1);
    
    firstname = firstPart + secondPart
  } 
  
  // This will turn O'neil into O'Neil
  if (firstname.includes("'")) {
    const parts = firstname.split("'")
    const firstPart = parts[0]
    let secondPart = parts[1]
    secondPart = secondPart.charAt(0).toUpperCase() + secondPart.slice(1);
    
    firstname = firstPart + secondPart
  }

  // Define firstname as an output at the bottom to be able to use the 'copy to property action and save the firstname'
  callback({
    outputFields: {
      firstname: firstname,
    }
  });
}

If you set 'firstname' as an output, you can use the copy to property action to store the firstname for this contact. I did not test this tho, so let me know if you run into any issues.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.