# Auto Populate Country Code based on Country

**URL:** <https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243>\
**Category:** CMS Development\
**Created:** [February 3, 2021, 11:37pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243 "2021-02-03T23:37:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![narendra1adhika](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/narendra1adhika/32/29892_2.png) [@narendra1adhika](https://community.hubspot.com/u/narendra1adhika)\
**Post date:** [February 3, 2021, 11:37pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243/1 "2021-02-03T23:37:16Z")

</div>

On contact, I have two property Country and Country Code.

I need to auto-update Country Code based on Country whenever a new contact is created.

I know I can use the workflow, but it is only useful if I have 4-5 countries. But if I have more than 100 countries, then it will become tough to handle that workflow.

is there any way where I don’t need to hard code each and every country in my workflow. Like store the country and country code in list and in run time get the value from there.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [February 5, 2021, 4:46pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243/2 "2021-02-05T16:46:40Z")

</div>

Hey @narendra1adhika

This looks like something where I would use a [webhook](https://developers.hubspot.com/docs/api/webhooks) that subscribes to contact creation.

An event would be sent to your app that would then would check the country and then send a patch back to HubSpot and update your contact accordingly.

But, doing this would require you to build an app and set up the process which might be just as much work as your proposed workflow.

@Bryantworks , @Kevin-C let me know if I totally overcomplicated this 😛

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [February 8, 2021, 3:24pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243/3 "2021-02-08T15:24:08Z")

</div>

Hey @narendra1adhika and thanks @dennisedson

Because this is on contact creation it could be done by populating a hidden form field via JS based on the selected value.

---

<div class="post-metadata">

**Author:** ![narendra1adhika](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/narendra1adhika/32/29892_2.png) [@narendra1adhika](https://community.hubspot.com/u/narendra1adhika)\
**Post date:** [February 8, 2021, 4:31pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243/4 "2021-02-08T16:31:37Z")

</div>

@Kevin-C Where will be that JS?

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [February 9, 2021, 5:25pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243/5 "2021-02-09T17:25:48Z")

</div>

Hey @narendra1adhika

[This is a very rough example.](https://codepen.io/kcornett/pen/dyOXpjb) It will need some work to ensure you’ve got all of you test cases covered. Hope it helps!

---

<div class="post-metadata">

**Author:** ![RBozeman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rbozeman/32/8786_2.png) [@RBozeman](https://community.hubspot.com/u/RBozeman)\
**Post date:** [September 27, 2022, 8:15pm UTC](https://community.hubspot.com/t/auto-populate-country-code-based-on-country/31243/6 "2022-09-27T20:15:50Z")

</div>

Hey @narendra1adhika,

As far as I know, with HubSpot’s current phone number formatting feature, you still have to manually select the country code. So, you’d have to find some workaround to get the country code to auto-populate.

I think that [Insycle](https://app.hubspot.com/portal-recommend/l?slug=ecosystem/marketplace/apps/marketing/data-management/insycle) could be of help here. Full disclosure, I work for Insycle, but it seems a good fit for your use case:

- Format your phone number field with a country code, based on location data.
- Autopopulate a “country code” field based on location data.
- Format phone numbers using many pre-built templates for popular formats.
- Build custom phone number formatting templates.

Hope that helps!

Best,

Ryan
