restrict country selection

Anubhav Srivas1
Tera Expert

Hi,

 

It is for a catalogue item, I'm trying to restrict users to select any other country rather than their home country.

This country data is coming from a custom table called " u_razor_access", which eventually is coming from the core_country table. 

 

screenshot 1: it is a custom table "u_razor_access"

the variable that holds the value is" what country is this for?" backend name "country"

 

screenshot 2: i tried to capture the logged in user country by using a lookup select box and a client script (screenshot 3).

 

Now, eventually i need to compare if the logged in user is selecting the correct country from the lookup select box.

that is comparing the values of "country & requested_for_country_1". if they don't match then it should clear the value and alert a message.

 

 

 

 

8 REPLIES 8

Hi, I tried your script and replaced the "home_country" with " requested_for_country_1" & "country" with "country" but it is always showing an error.

Community Alums
Not applicable

could you please send me the snapshot of that error..!

 

when i do an alert of the fields one give the sys_is and the other gives the ISO short name, that's the problem. how can we compare them if the values are odd? the error is the same message that we are alerting

Community Alums
Not applicable

Hello,

 

can you try this:-

 

CCS:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

// Fetch the user's home country from the custom table 'u_razor_access'
var userSysId = g_user.userID;
var userHomeCountry = '';

var ga = new GlideAjax('GetUserHomeCountry');
ga.addParam('sys_id', userSysId);
ga.getXMLAnswer(function(response) {
userHomeCountry = response;

// Fetch the selected country value
var selectedCountry = g_form.getValue('country'); // Replace 'country' with your variable name

// Compare the selected country with the user's home country
if (selectedCountry !== userHomeCountry) {
// Clear the selected value
g_form.clearValue('country');
// Display an alert message
g_form.addErrorMessage('You can only select your home country.');
}
});
}

 

 

Script Include:

var GetUserHomeCountry = Class.create();
GetUserHomeCountry.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getHomeCountry: function() {
var userSysId = this.getParameter('sys_id');
var homeCountry = '';

var razorAccessGR = new GlideRecord('u_razor_access');
razorAccessGR.addQuery('user', userSysId);
razorAccessGR.query();
if (razorAccessGR.next()) {
homeCountry = razorAccessGR.getValue('home_country'); // Replace 'home_country' with the correct field name in u_razor_access
}

return homeCountry;
}
});