Changing hs_language with within workflow

Hi folks!

I am struggling a bit with changing hs_language within a workflow.

I have the information for the preferred language on the company properties in an single line field. The information is exactly in the format hs_language is made of (de-de, de-at and so on).

But I need the information mirrored to the contact as well. I cannot copy to hs_language - it does not show up the my dropdown of fields to copy to. I guess it is blocked because it is a hubspot (dropdown) field which cannot be loaded with any other values than the given.

Anyone has an idea how I can copy the information from the companies single line text to hs_language?

The only thing I came up was in a biiiiiiiig workflow with a lot if “ifs” to map every line. thats a lot… and would cost me ages and a headache.

Hey @MartecDaniel,

thank you for reaching out to the community. Sounds like an interesting case.

I’ve tried recreating it, and it’s the same for me as you are describing it. So it appears HubSpot is blocking that property from being copied to.

If/thens sounds like a lot of hassle indeed and wouldn’t feel smart. Do you by any chance have an Operations Hub Pro license? If so, I would be able to write a short piece of code for a custom code action that would be able to do the trick.

Cheers,

Chriso

Hey @ChrisoKlepke ,

yes we have the OperationsHub. The problem is, I can’t find the company property prefered_language in the custom code section (I can of course create a custom property with the copied value from the company but would like to avoid that. )

Hey @MartecDaniel,

no worries, I try my best to walk you through that. But just in case I like summerize to make sure I understood you correctly.

You have a company-based workflow that runs, probably on something preferred_language is known.

And you like to copy the language code to all associated contacts of that company.

Cheers,

Chriso

Hey again,

if my assumption from earlier were correct, this should be the code to get you going:

import os
from pprint import pprint
from hubspot import HubSpot
from hubspot.crm.contacts import (
 ApiException as ContactApiException,
 SimplePublicObjectInput,
)
from hubspot.crm.companies import ApiException as CompanyApiException

def main(event):

 hubspot = HubSpot(access_token=os.getenv("hs_access_token"))

 company_lang = event.get("inputFields").get("preferred_language")
 company_id = event.get("object").get("objectId")

 try:
 get_assoc_contacts = hubspot.crm.companies.associations_api.get_all(
 company_id=company_id, to_object_type="CONTACT"
 )
 # pprint(get_assoc_contacts) # uncomment for debug

 except CompanyApiException as exception:
 pprint(exception)

 for contact in get_assoc_contacts.results:
 contact_id = contact.id

 update_properties = SimplePublicObjectInput(
 properties={"hs_language": company_lang}
 )

 try:
 update_contact_lang = hubspot.crm.contacts.basic_api.update(
 contact_id=contact_id, simple_public_object_input=update_properties
 )
 # pprint(update_contact_lang) # uncomment for debug
 except ContactApiException as exception:
 pprint(exception)

 return

Make sure to include the property which is storing the company language in the section Properties to include in code as preferred_language.

Also make sure to include your access token as hs_access_token and see if the Private App has the scopes for writing and reading companies and contacts.

Please let me know how it goes.

If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.

Cheers,

Chriso