How to populate a phone number(E164)when the territory selector is chosen from the drop down list

Community Alums
Not applicable

How to populate a phone number based on the territory selector choice list Exampe: If the phone number is 13126266799 then North America needs to populated in the selector choice list same like if the phone number is +1 613-800-6513 then Canada needs to populated.

Anyone please help me on this.

8 REPLIES 8

-O-
Kilo Patron
Kilo Patron

In any case, if either the Phone number or the Country is to be selected from a list, you can make the 1st field o Select Box and you can configure a Service catalog data lookup:

find_real_file.png

to fill in the 2nd field.

Perhaps @Mark Roethof's article Catalog Data Lookup Definition on any table, eliminating Catalog Client Scripting will also help.

Community Alums
Not applicable
Hi , I am having only one field that is E164 type and I need the same,If the country is chosen as Australia from the drop down then the phone number is set to +61 8 7150 1149 and I need to set it for all mentioned in the list Is that possible ?

Well, I'm not sure why I thought this is about some Catalog Item, it clearly isn't. As for the original problem, the requirement is not supported OOB. Though it seems like one deals with two fields, the drop-down and the text entry are a single field and only the text entry is exposed through the g_form API.

If you are OK with DOM manipulation a solution would be to create on onLoad Client Script for Incident that wires up an event listener, so you can know when the country has been selected:

function onLoad () {
	var element = 'u_bridge_phone_number',
		select = g_form.getControl('country_' + g_form.getTableName() + '.' + element);

	if (select && typeof select.addEventListener == 'function')
		select.addEventListener('change', callChange(select));

	function callChange (select) {
		var oldValue = getValueOfSelect(select);

		onChange(select, oldValue, oldValue, true, false);

		return function (event) {
			onChange(event.target, oldValue, getValueOfSelect(event.target), false, false);
		};
	}

	function getValueOfSelect (select) {
		return select.selectedIndex > -1 ? select.options[select.selectedIndex].textContent : '';
	}

	function onChange (control, oldValue, newValue, isLoading, isTemplate) {
		// This is where one can implement any logic that must run when the
		// country is changed. E.g. do a GlideAjax call to fetch the number
		// Based on newValue, which will be a label, like North America, etc...
		if (isLoading || newValue === '') {
			//return;
		}

		console.log('change', control, oldValue, newValue, isLoading, isTemplate);
	}
}

You can than implement the lookup in function change, where the comments say. You should create lookup table to store the country - phone number list. With help of GlideAjax, based on the selected label, you can obtain the phone number to use - this can be filled using the regular g_form.setValue() call.

A week point of the solution (besides the DOM manipulation part and only working in UI16!, of course) is localization. The code uses the drop-down label for newValue and oldValue. This is to enable differentiation between Canadian and United Sates phone number which all start with 1+. But if an agent uses a non-English locale for himself, the label will no longer be in English and your solution will not work for him. This can be solved either by re-implementing function getValueOfSelect to return something else and select the phone number by that value, or by selecting the phone number through a Decision Table based on localized labels.

Hope this all helps.

But there is in important fact to consider: it will NOT be possible to define two countries with the same calling prefix. So if you want both Canada and the United States to show up in the list of countries, well that is not possible. The two countries share the international prefix under North America. You could Create two new additional entries called Canada and United States using international prefixes +1780 and + 1312, but if anybody else will need to use Canadian or United States number with different prefixed, well, it is going to be messy.

If you ask me, I would just move the selection of the country into a different field, where the list of countries is NOT tied to the E164 validation tables (where only North America "can" exist).