I am having the below on change client script running on a device type variable, need to update the

Archana23
Tera Contributor

I am having the below on change client script running on a device type variable, need to update the countries in one new  system property and need to call it in this client script.

Please help me in script.

Thanks in advance.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading) {
      return;
   }
   g_form.clearOptions('delivery_location')
   var usrcountry = g_form.getValue('country')
 
    if((newValue == 'Standard Office/' || newValue == 'Standard Office Laptop 15"' || newValue == 'Standard Mobile Workstation' || newValue == 'Convertible Laptop' || newValue == 'HP Series Pro 524pn - 24"') && ( usrcountry == 'Canada' || usrcountry == 'United States of America' || usrcountry == 'Finland' || usrcountry == 'Estonia' || usrcountry == 'Ireland'  )){
    g_form.addOption( 'select_delivery_location' , '' , '-- None --' );
     getMessage('Home',function(msg){
       
    g_form.addOption('select_delivery_location','Home',msg)});
    //g_form.addOption('select_delivery_location','Home','Home')
     getMessage('SE Office',function(msg){
       
    g_form.addOption('select_delivery_location','SE Office',msg)});
   } else {
    g_form.addOption( 'select_delivery_location' , '' , '-- None --' );
     getMessage('SE Office',function(msg){
       
    g_form.addOption('select_delivery_location','SE Office',msg)});
   }

   //Type appropriate comment here, and begin script below
   
}
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Archana23 

create system property and use GlideAjax.

Within the GlideAjax function use gs.getProperty() and compare

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I have tried like this, but no alerts or errors coming.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    g_form.clearOptions('select_delivery_location');
    var usrcountry = g_form.getValue('country');
    var ga = new GlideAjax('SE_HARDWARE_REQUEST'); // The name of the Script Include
    ga.addParam('sys_id', 'getSpecialCountries'); // The method in Script Include to call
    function getResponse(response) {
        var answer = response;

       
        alert(answer);
        var isSpecialCountry = answer.includes(usrcountry);
        alert('Is special country: ' + isSpecialCountry); // Debugging check for country match
        //
        alert(isSpecialCountry);

        if ((newValue == 'Standard Office/Traveler Laptop 14"' || newValue == 'Standard Office Laptop 15"' || newValue == 'Standard Mobile Workstation' || newValue == 'Convertible Laptop' || newValue == 'HP Series Pro 524pn - 24"') && isSpecialCountry) {
            g_form.addOption('select_delivery_location', '', '-- None --');
            getMessage('Home', function(msg) {

                g_form.addOption('select_delivery_location', 'Home', msg);
            });

            //g_form.addOption('select_delivery_location','Home','Home')
            getMessage('SE Office', function(msg) {

                g_form.addOption('select_delivery_location', 'SE Office', msg);
            });
        } else {
            g_form.addOption('select_delivery_location', '', '-- None --');
            getMessage('SE Office', function(msg) {

                g_form.addOption('select_delivery_location', 'SE Office', msg);
            });
        }
    }

    //Type appropriate comment here, and begin script below

}

This is the script include

 

getSpecialCountries: function() {
        var countries = gs.getProperty('SE_home_option', '').split(',');
        return countries.join(',');
    },


    type: 'SE_HARDWARE_REQUEST'

Try the following in your client script to call that function in the script include, assuming the name of that is 

 

	var ga = new GlideAjax('SE_HARDWARE_REQUEST');       //name of script include
	ga.addParam('sysparm_name', 'getSpecialCountries');       //name of function on script include
	ga.getXMLAnswer(getResponse);    

 

and add:

 

		alert('response = ' + response);

 

in the getResponse function to see what is returned.