Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

REGION FIELD IN CLEINT SCRIPT

avinashdubey103
Tera Guru

Can somebody help want wrong i am doing in the below on load  script 

function onLoad() {
 
    var userRegion = g_user.location.u_region;
 
    var field1 = g_form.getControl('u_shipping_label');
    var field2 = g_form.getControl('u_shipping_return_label');
   

    alert('Region is'+userRegion);


    if (userRegion == 'AMERICAS' ||userRegion == 'EMEA' ) {

        g_form.setDisplay('field1', true);
        g_form.setDisplay('field2', true);
    } else {
 
        g_form.setDisplay('field1', false);
        g_form.setDisplay('field2', false);
    }
}



5 REPLIES 5

Hi , I have tried using glideajax 

can you please help me now what is wrong 

var GetUserRegion = Class.create();
GetUserRegion.prototype = Object.extendsObject(AbstractAjaxProcessor, {

// This function will fetch the user's region based on their location
getRegion: function() {
var userId = gs.getUserID(); // Get the current user's Sys ID

gs.info('Bhagat Singh: Fetching region for user with Sys ID: ' + userId); // Log user ID

var userGR = new GlideRecord('sys_user'); // Query the User table
if (userGR.get(userId)) {
// Dot-walk to get the region from the user's location
var userRegion = userGR.location.u_region; // Dot-walking to fetch the u_region field directly

// Log the fetched region
gs.info('Bhagat Singh: Region fetched from location: ' + userRegion); // Log the region

// Ensure we return a default value if no region is found
return userRegion || ''; // Return an empty string if no region is found
} else {
gs.error('Bhagat Singh: No user record found for Sys ID: ' + userId); // Log error if no user record is found
}

return ''; // Return an empty string if no region is found
}
});
var GetUserRegion = Class.create();
GetUserRegion.prototype = Object.extendsObject(AbstractAjaxProcessor, {


getRegion: function() {
var userId = gs.getUserID();
gs.info('Bhagat Singh: Fetching region for user with Sys ID: ' + userId); // Log user ID

var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {

var userRegion = userGR.location.u_region; // Dot-walking to fetch the u_region field directly

// Log the fetched region
gs.info('Bhagat Singh: Region fetched from location: ' + userRegion); // Log the region

// Ensure we return a default value if no region is found
return userRegion || ''; // Return an empty string if no region is found
} else {
gs.error('Bhagat Singh: No user record found for Sys ID: ' + userId); // Log error if no user record is found
}

return '';
}
});