HI All

basha shaik
Tera Contributor

I Have 3 fields.

1. user--that user Refrance table

2.Region-----that is Region Refrance table

3.Team------that is select box

 

whenever user select user name Automatic Region should be populated and under team select choice visible not for all

1 REPLY 1

Pradeep Thipani
Mega Sage

Hi @basha shaik ,

 

You can write a script include and fetch the users region and call the script include in client script. Find below example of script include and client script you can modify names based on your values.

 

Script Include:

 

// Script Include: GetUserRegion
var GetUserRegion = Class.create();
GetUserRegion.prototype = {
    initialize: function() {},

    getRegion: function() {
        var userId = this.getParameter('sysparm_user_id');
        var user = new GlideRecord('sys_user'); // Assuming 'sys_user' is the user table
        if (user.get(userId)) {
            return user.region; // Replace 'region' with the actual field name in sys_user for region
        }
        return '';
    },

    type: 'GetUserRegion'
};

 

Client Script OnChange:

// Client Script: Populate Region based on selected User
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return; // Exit if the form is loading or no user is selected
    }

    // Make a GlideAjax call to fetch the region for the selected user
    var ga = new GlideAjax('GetUserRegion');
    ga.addParam('sysparm_name', 'getRegion');
    ga.addParam('sysparm_user_id', newValue); // Pass the selected user ID
    ga.getXMLAnswer(function(response) {
        g_form.setValue('region', response); // Set the region field with the response
    });

    // Optionally reset the Team field here if needed
    g_form.setValue('team', ''); // Reset the team field
}

Thanks,

Pradeep

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep