Most Recent

Blog Post

Converting Country Codes in Pega

Converting Country Codes in Pega

From my previous articles on "Country Picker Controls" and “Displaying Country Names" it follows that an application could work with either 2-letter or 3-letter country codes; or both. When designing and developing Pega from the “center out” there comes a moment that you might integrate with some external system that expects either the shortest or slightly longer notation of such codes.

Note that both enumerations are perfectly valid and within the same ISO standardization. In practice you just need to cope with the specification of API of that remote system. Hence conversion between these two notations for country codes.

The following Java code can be used to convert a standard alpha-3 country code into an ISO 3166 alpha-2 letter code:

public static String convertISO3Country(String code) {
    String[] countries = Locale.getISOCountries();
    String countrycode = "";
    for (int i = 0; i < countries.length; i++) {
        Locale locale = new Locale("", countries[i]);
        if (locale.getISO3Country().equalsIgnoreCase(code)) {
            countrycode = locale.getISOCountry();
}
    }
    return countrycode;
}

Instruction: Just copy-n-paste all but the first and last line. Since Pega auto-generates the declaration from the Parameters’ definition, you only need the function’s body and the return line as Java source in a suitable new function rule. The result should look like: Source code for convertISO3Country(String)

You can use the following parameter signature and documentation to reconstruct this business rule:

Input parameters

code 3-letter country code conform ISO 3166 String Text

Output

String Text

Description

Converts given 3-letter input Param.code into 2-letter country code; otherwise returns empty String "".

Usage

Inline function call to set some country code property.

Remember: Enable “Function ready to be compiled?” checkbox, Save and Check-In rule and then Generate function or library as a whole.

Exemplary calls

  • @convertISO3Country(.pyCountryCode)
  • @convertISO3Country(Param.CountryCode)

Enjoy! -Edgar

[Edgar] (5/5/2021 11:24:43 AM)

 

Twitter Feed

@edgarverburg

Bio

About Edgar

Edgar is a software engineer with experience in TIBCO Middleware and Pega Case Managemement. He holds a master's degree in Computer Science with a specialization in Data Visualization & Computer Graphics.

In his spare time Edgar reads SOS and Empire, mixes house music, blogs and writes film reviews or goes running.


Currently employed by SynTouch he is specifically looking for a PRPC project. Feel free to contact him for challenging assignments through LinkedIn.