- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 03:44 PM
I have created system property to include about 5 countries sys_ids(India, Africa, Japan, China, Sri Lanka), would like to call this system property sys_id's in the client script, 'Country' variable is a reference field to country table.
If one of these countries is not selected then the below condition in client script it should clear the variable values.
Script Include -
Client script -
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:27 PM
Hi @Varun Sai
Oops. The actionName variable is missing from the script above.
function onSubmit() {
//Add these lines to your script
if (g_scratchpad.isFormValid){
return true;
}
var actionName = g_form.getActionName();
var ga = new GlideAjax('County_check');
ga.addParam('sysparm_name', 'getPropertyCountry');
ga.getXMLAnswer(function(answer){
var countries = answer;
var user_country = g_form.getValue('u_country');
//If the selected User Countries is not in 5 countries
if(countries.indexOf(user_country) == -1){
g_form.clearValue('u_lead');
g_form.clearValue('c_approver');
return false;
}
//Add this lines to your script
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
});
return false;
}
This is my script include. (Make sure the Client callable checkbox is checked)
var County_check = Class.create();
County_check.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPropertyCountry: function() {
return gs.getProperty('glide.exclude.countries'); // Has 5 countries sys_id's - India, Africa, Japan, China, Sri Lanka
},
type: 'County_check'
});
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:13 PM
Hi Tai,
I tried your solution and I am getting the JavaScript error on the portal page.
I put in alerts and didn't see the country come up on the browser too.
Not sure what's wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:27 PM
Hi @Varun Sai
Oops. The actionName variable is missing from the script above.
function onSubmit() {
//Add these lines to your script
if (g_scratchpad.isFormValid){
return true;
}
var actionName = g_form.getActionName();
var ga = new GlideAjax('County_check');
ga.addParam('sysparm_name', 'getPropertyCountry');
ga.getXMLAnswer(function(answer){
var countries = answer;
var user_country = g_form.getValue('u_country');
//If the selected User Countries is not in 5 countries
if(countries.indexOf(user_country) == -1){
g_form.clearValue('u_lead');
g_form.clearValue('c_approver');
return false;
}
//Add this lines to your script
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
});
return false;
}
This is my script include. (Make sure the Client callable checkbox is checked)
var County_check = Class.create();
County_check.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPropertyCountry: function() {
return gs.getProperty('glide.exclude.countries'); // Has 5 countries sys_id's - India, Africa, Japan, China, Sri Lanka
},
type: 'County_check'
});
Cheers,
Tai Vu