how to get pre-populate country code before phone number in record producer

prathap kumar 1
Tera Contributor

Hello Experts,

Can anyone help me in getting the Country code pre-defined in Phone number field and changes with change in country in record producer. Desired requirement is given below FYI:

thanks in advance.

Regards,

Prathap

4 REPLIES 4

Gaurav Bajaj
Kilo Sage

Hi Pratahp



Please follow below step.


1) Have the mapping of the country and country codes in a lookup table (could be country table itself).


2) Create an Onchange Catalog client script.


3) Pick the value of the country from country field, then pass it on to the server with glide ajax and then from server return the country code (through script include).


4) Use g_form.setValue to append the country code returned from server to the phone number field.




Let me know if you need help with the script.



Thanks


Gaurav


Hello Gaurav ,



Can you please help with the code for country code as asked in the above query.


prathap kumar 1
Tera Contributor

Can u help me script please


Hi,



Please follow the below step.



1) Add a new field to the country table as phone code.


2) Populate values of phone codes for each of the countries in this new field ( This will work as a lookup).


3) Add two variables to the Record producer e.g. Country (a reference to county table) and phone Number ( SIngle line text).


4) Create a new catalog client script to auto-populate the.



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




    //Type appropriate comment here, and begin script below


    var response=g_form.getReference('Country',CodeCallBack);





}




function CodeCallBack(response){





var phoneCode=response.u_phone_code;


phoneCode ="+"+phoneCode;


g_form.setValue('phone_number',phoneCode);





}


















find_real_file.png



find_real_file.png



You can always modify the script as per your need as this is just a sample script to demonstrate the basic example.




Thanks


Gaurav