how to display list of record to Callers field based on Account selected on the form.

Neelavathi M
Tera Contributor

Hi All,

I have a requirement to Populate the list of Callers only for the Selected Account, and Account table has related list called "Contacts" where we have users and these users are also present in sys_user table  and on the Actual Form , only these users has to be populated for Caller's field (reference : sys_user)based on Accounts.

 

NeelavathiM_1-1689758589510.png

 

 

NeelavathiM_0-1689758482778.png

 

To Achieve this i have created Client Script and Script include:  i am able to get the Account and no of contacts related to Account, but failing to display those contacts to caller's field ,please  help me to achieve this.

 

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
}
 
    var account = g_form.getValue('u_account');
alert(g_form.getValue('u_account'));
 
    var ga = new GlideAjax('CallerUtils');
    ga.addParam('sysparm_name', 'getCallersByAccount');
    ga.addParam('sysparm_account', account);
    ga.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        var callers = JSON.parse(answer);
 
        // Process the list of callers
        for (var i = 0; i < callers.length; i++) {
            var caller = callers[i];
             alert('Caller Name: ' + u_caller_id.name);
                  alert('Caller Email: ' + u_caller_id.email);
        }
    });
    //Type appropriate comment here, and begin script below
 
}
 
Script Include:

var CallerUtils = Class.create();
CallerUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCallersByAccount: function() {
var account = this.getParameter('sysparm_account');
gs.log('account:::::::::::::' + account);
var callerList = [];
var userGR = new GlideRecord('customer_contact');
userGR.addQuery('account', account);
//userGR.addQuery('active', true);
userGR.query();
gs.log('Account++' + userGR.getRowCount());
while (userGR.next()) {
var contactEmail = userGR.getValue('email');
gs.log('Email++' + contactEmail);
var gr = new GlideRecord('sys_user');
gr.addQuery('email', contactEmail);
gr.addActiveQuery();
gr.query();
while (gr.next()) {
var userEmail = gr.getValue('sys_id');
}
callerList.push(userEmail);

}
return callerList;
},
type: 'CallerUtils'
});

 

Please let me know where the changes has to be made to get the Contacts in Callers field.

1 ACCEPTED SOLUTION

Arun_S1
Tera Guru
Tera Guru

@Neelavathi M Try the below.

1. Right click on the caller_id field and configure dictionary and select Advanced for the "Use Reference Qualifier" and add the below code in the "Reference qual".

 

javascript&colon; 'sys_idIN'+new query_user().fromAccount(current.u_account);

 

 

2. Create a new script include with the name "query_user" without enabling "client callable" checkbox and add the below script

 

var query_user = Class.create();
query_user.prototype = {
    initialize: function() {},
    fromAccount: function(account) {
        if (account != null && account != '') {
            var callerList = [];
            var userGR = new GlideRecord('customer_contact');
            userGR.addQuery('account', account);
            userGR.query();
            while (userGR.next()) {
                var contactEmail = userGR.getValue('email');
                var gr = new GlideRecord('sys_user');
                gr.addQuery('email', contactEmail);
                gr.addActiveQuery();
                gr.query();
                if (gr.next()) {
                    callerList.push(gr.sys_id);
                }


            }
            return callerList;

        }
        return '';
    },

    type: 'query_user'
};

 

 

Please mark the appropriate response as correct answer and helpful.

Thanks!!

View solution in original post

3 REPLIES 3

umaaggarwal
Giga Guru
Giga Guru

Is the account field available on user table ? If yes, it can be done using reference qualifier 

Arun_S1
Tera Guru
Tera Guru

@Neelavathi M Try the below.

1. Right click on the caller_id field and configure dictionary and select Advanced for the "Use Reference Qualifier" and add the below code in the "Reference qual".

 

javascript&colon; 'sys_idIN'+new query_user().fromAccount(current.u_account);

 

 

2. Create a new script include with the name "query_user" without enabling "client callable" checkbox and add the below script

 

var query_user = Class.create();
query_user.prototype = {
    initialize: function() {},
    fromAccount: function(account) {
        if (account != null && account != '') {
            var callerList = [];
            var userGR = new GlideRecord('customer_contact');
            userGR.addQuery('account', account);
            userGR.query();
            while (userGR.next()) {
                var contactEmail = userGR.getValue('email');
                var gr = new GlideRecord('sys_user');
                gr.addQuery('email', contactEmail);
                gr.addActiveQuery();
                gr.query();
                if (gr.next()) {
                    callerList.push(gr.sys_id);
                }


            }
            return callerList;

        }
        return '';
    },

    type: 'query_user'
};

 

 

Please mark the appropriate response as correct answer and helpful.

Thanks!!

Hi, solution is working , but this caller field used in other custom table as well, so it is affecting other table, not able to select callers in other table, so can you please suggest , where the changes has to be made.

 

I tried by adding javascript&colon; if (current.target_table == 'u_sr_xxx')

                'sys_idIN'+new query_user().fromAccount(current.u_account); but it is not working.