- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-19-2023 02:30 AM
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.
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:
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-19-2023 05:31 AM - edited ā07-19-2023 05:33 AM
@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: '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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-19-2023 04:11 AM
Is the account field available on user table ? If yes, it can be done using reference qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-19-2023 05:31 AM - edited ā07-19-2023 05:33 AM
@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: '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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2023 12:17 AM
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: if (current.target_table == 'u_sr_xxx')
'sys_idIN'+new query_user().fromAccount(current.u_account); but it is not working.