Multiple sys_IDs on system property, how to call in client script to verify condition

Varun Sai
Tera Contributor

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

getPropertyCountry: function() {
        return gs.getProperty('glide.exclude.countries');  // Has 5 countries sys_id's - India, Africa, Japan, China, Sri Lanka
    },
 

Client script

function onSubmit() {

        var ga = new GlideAjax('County_check');
        ga.addParam('sysparm_name', 'getPropertyCountry');
        ga.getXML(myCallBack);

        function myCallBack(response) {
            var prop = response.responseXML.documentElement.getAttribute('answer');
 
            var user_country = g_form.getValue('u_country');  

            if (user_country !=  prop){     //only if the selected country is not any one of India, Africa, Japan, China, Sri Lanka then below conditions needs to be applied
                g_form.clearValue('u_lead');
                g_form.clearValue('c_approver');
                return false;
            }
 
But I am getting an error and it's not working as the client script is not pulling the country sys_ID from the system property I think.
What am I missing here, appreciate any help.
1 ACCEPTED SOLUTION

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

View solution in original post

6 REPLIES 6

Varun Sai
Tera Contributor

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.

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