Expand my Community achievements bar.

SOLVED

How to populate list of Countries with 3 letter code as value in dropdown field?

Avatar

Level 4

Hi everyone,
I'm working on Adaptive form in which I've dropdown for Country Names. Now, I want to populate the list of full country name, but the values should be their 3-letter code. Something like below.

 

<option value="AZE">Azerbaijan</option>
<option value="AUS">Australia</option>

 

Adding 105 items manually to the dropdown field is lengthy. So, I tried Function Output feature of AF but I can only populate country names without their codes like below:

 

<option value="United States">United States</option>
<option value="Norway">Norway</option>

Got above output by using this:

const countryList = [
	"Afghanistan",
	"Albania",
	"Algeria",
	"American Samoa"];

But can't leverage this:

const countryListAlpha3 = {
    "AFG": "Afghanistan",
    "ALB": "Albania",
    "DZA": "Algeria"};

Using country list from this (line 528 have 3-letter codes) GitHub link. I'm not sure how to add value to dropdown items.

Can someone please help me to accomplish this?

Regards,
Sesmic

 

 

1 Accepted Solution

Avatar

Correct answer by
Employee
9 Replies

Avatar

Employee

you can use publicly available API to get the list of countries and populate the drop-down list

I have written an article on this

https://experienceleague.adobe.com/docs/experience-manager-learn/forms/some-useful-integrations/geon...

 

let me know if you have trouble getting this to work on your system

Avatar

Correct answer by
Employee

Avatar

Level 4

Hi @gbedekar 
Thanks for the reply!
I read your article while learning AF and implemented it. Felt awesome.
But, in current use case there's no dependent DropDownList just country names. I simply want list of countries with their codes as value because the submitted value is important after submission. 

Avatar

Employee

you can follow the article to implement a form data model service to fetch the countries list from any of the publicly available api

https://www.universal-tutorial.com/rest-apis/free-rest-api-for-country-state-city

 

This API returns the countries and code associated with it

lets have a call

send a private message

 

Avatar

Level 4

Appreciate your effort.
For item load property, is there any way to save values fast or manually entering them is last resort?
Will look into API idea you shared, but afraid client will like it or not.
Anyways thanks @gbedekar . Will message you if needed.

Avatar

Employee

there are two options

one is to find REST API that returns the data in the format your want - Drawback you may have to pay for it or if its free there is no guarantee that it will be up 24/7

The other option is to write your custom servlet that will return the json of the countries in the format you want

or you can use item load path property.

In any case you will have to go through the effort of creating the countries list 

Avatar

Level 4

Will it not be possible to accomplish this with Function Output or Rule editor? My JS is not good, so couldn't get the expected result.