Auto Populate all the users when site code is selected

NirajK4122
Tera Contributor

I have a requirement in which when I select Site code in catlog item which is reference to cmn_location then all the associated user related to that site code should be populated in such a way that, we can select multiple user through check box.

2 REPLIES 2

Sujatha V M
Kilo Patron
Kilo Patron

@NirajK4122 Assuming you have a dependent field to display the users for selection based on "Site" code. 

 

You can add reference qualifier as below on field which lists the users based on location. 

 

Table : User [sys_user]

 

javascript&colon; 'location='+current.variables.<your field>

 

SujathaVM_1-1712079288480.png

 

Note: If reference field, try to pass the sys_id. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Amit Pandey
Kilo Sage

Hi @NirajK4122 

 

Can you try writing client script with following code-

 

function onChangeSiteCode() {
    var siteCode = g_form.getValue('site_code'); // Get the selected Site Code value
    var multiSelectField = 'associated_users'; // Change this to the actual name of your multi-select field
    g_form.clearOptions(multiSelectField);
    var userGr = new GlideRecord('sys_user');
    userGr.addQuery('site_code', siteCode);
    userGr.query();

    while (userGr.next()) {
        var userSysID = userGr.getUniqueValue();
        var userName = userGr.getValue('name'); // Change this to the appropriate field displaying user name
        g_form.addOption(multiSelectField, userSysID, userName);
    }
}