⚙ Operations Hub

DSwanich8
Participante

Checking for - or ' in a name field

resolver

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 Soluciones aceptada
Teun
Solución
Experto reconocido | Partner nivel Diamond
Experto reconocido | Partner nivel Diamond

Checking for - or ' in a name field

resolver

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.


Ver la solución en mensaje original publicado

2 Respuestas 2
MSaye
Participante

Checking for - or ' in a name field

resolver

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 Me gusta
Teun
Solución
Experto reconocido | Partner nivel Diamond
Experto reconocido | Partner nivel Diamond

Checking for - or ' in a name field

resolver

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.