How to fetch data using phone number with or without country code in Pega?

Hello,

I’m working on a Pega application where I fetch customer details based on the phone number entered in the UI. The data is retrieved using an activity with Obj-Open, matching the phone number stored in the database.

However, users might enter the phone number:

  • With country code (e.g., +91XXXXXXXX or 91XXXXXXX )
  • Without country code (e.g., 876XXXXXX)

I want the system to retrieve the record regardless of the format entered.

Current Configuration:

  • Using Obj-Open in an activity (Get Data) on a data class.
  • Matching is done using .PhoneNumber from the Primary page.
  • Phone numbers in the database are currently stored with country code.

What I Need:

  • A way to normalize the phone number (strip country code or non-numeric characters).
  • Possibly store and compare with a consistent what phone number format from call.
  • Suggestions on best practices for matching phone numbers reliably (regardless of format).

Has anyone implemented something similar? What’s the recommended approach?

Any help or shared pattern would be appreciated.

Thanks!

@sharadavangimalla

I think you should identify the possible formats and use if-else conditions to process each format type appropriately.

For example, if phoneNumber starts with +91, do this. I don’t think you would find an out-of-the-box solution that processes Indian phone number formats.

@sharadavangimalla use edit input for the phone number property and format it based on the required db format. This way you will keep the format consistent irrespective of how the user enters the number.

Hi @sharadavangimalla

The best way is to first clean the user input using a Data Transform—remove all non-numeric characters using @String.pxReplaceAll() and get the last 10 digits with @String.substring(). Instead of Obj-Open, use Obj-Browse with a filter that matches the last 10 digits of the phone number stored in the DB. This way, whether the input has +91, 91, or nothing, it’ll still match. If possible, store a normalized version of phone numbers in the DB for consistency.

@sharadavangimalla

why don’t you use obj-browse before Obj-open with filter condition in obj-browser will be Phone Number contains = pass the user entered phone number and pass the fetched phone number from DB to Obj-Open.

@sharadavangimalla To fetch customer data using phone numbers with or without country code, you can first clean the input by removing any non-numeric characters like “+” or spaces and then keep only the last 10 digits of the number. You can do this using a Data Transform or a Java step in your activity. Create a new property called NormalizedPhone and use it for matching. Also, in your database records, create another property NormalizedPhoneNumber that stores only the last 10 digits of the stored phone number. Use Obj-Browse instead of Obj-Open to search records where NormalizedPhone matches NormalizedPhoneNumber. This way, the system will find the record correctly regardless of whether the user enters the phone number with or without a country code. You can also make NormalizedPhoneNumber a database column for better performance.