⚙ Operations Hub

DSwanich8
参加者

Checking for - or ' in a name field

解決

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件の承認済みベストアンサー
Teun
解決策
名誉エキスパート | Elite Partner
名誉エキスパート | Elite Partner

Checking for - or ' in a name field

解決

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.


元の投稿で解決策を見る

2件の返信
MSaye
参加者

Checking for - or ' in a name field

解決

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 いいね!
Teun
解決策
名誉エキスパート | Elite Partner
名誉エキスパート | Elite Partner

Checking for - or ' in a name field

解決

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.