- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2024 11:33 PM
Hi Team,
we have a reference field(u_approver) on account(customer_account) table form, which refer to contacts(customer_contact) table.
I want a reference qualifier on u_approver field to display all the active contacts from current account and active contacts from parent account combined.
example:
In Account A i have c1, c2, c3 contacts.
And Account A is parent of Account B which ha c4 and c5 contacts.
I have a refence field called Approver on Account Table.
If i search for contact to select on the Account B(by using magnifying glass beside approver field on the form) i need to see c1, c2, c3, c4, c5 records.
If i search for contact to select on the Account A(by using magnifying glass beside approver field on the form) i need to see c1, c2, c3 records only.
can anyone please provide me the reference qualifier script to acheive the above.
Thanks in advance,
Hari Kishan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 01:08 AM
Hi @HARI KISHAN GVS
- Right click on Approver field name and Navigate to the dictionary entry for the Approver field on the Account table.
- Set the Reference Qual to Dynamic and use Advanced script option.
Custom script: change the values according to your correct backend names :
(function() {
var approverList = [];
// Get the current account from the form
var currentAccount = g_form.getValue('sys_id'); // assuming sys_id is the field holding current account ID
if (!currentAccount) {
// If we can’t find the current account, return an empty list to avoid errors
return 'sys_idIN' + approverList.join(‘,’);
}
// Get active contacts for the current account
var contactGR = new GlideRecord('contact'); // change ‘contact’ to your actual contact table name if different
contactGR.addQuery('account', currentAccount);
contactGR.addQuery('active', true);
contactGR.query();
while (contactGR.next()) {
approverList.push(contactGR.sys_id.toString());
}
// Get the parent account of the current account
var accountGR = new GlideRecord('account'); // change ‘account’ to your actual account table name if different
if (accountGR.get(currentAccount) && accountGR.parent) {
var parentAccount = accountGR.parent.sys_id.toString();
// Get active contacts for the parent account
contactGR.initialize();
contactGR.addQuery('account', parentAccount);
contactGR.addQuery('active', true);
contactGR.query();
while (contactGR.next()) {
approverList.push(contactGR.sys_id.toString());
}
}
// Return the combined list of approver sys_ids
return 'sys_idIN' + approverList.join(',');
})();
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 01:08 AM
Hi @HARI KISHAN GVS
- Right click on Approver field name and Navigate to the dictionary entry for the Approver field on the Account table.
- Set the Reference Qual to Dynamic and use Advanced script option.
Custom script: change the values according to your correct backend names :
(function() {
var approverList = [];
// Get the current account from the form
var currentAccount = g_form.getValue('sys_id'); // assuming sys_id is the field holding current account ID
if (!currentAccount) {
// If we can’t find the current account, return an empty list to avoid errors
return 'sys_idIN' + approverList.join(‘,’);
}
// Get active contacts for the current account
var contactGR = new GlideRecord('contact'); // change ‘contact’ to your actual contact table name if different
contactGR.addQuery('account', currentAccount);
contactGR.addQuery('active', true);
contactGR.query();
while (contactGR.next()) {
approverList.push(contactGR.sys_id.toString());
}
// Get the parent account of the current account
var accountGR = new GlideRecord('account'); // change ‘account’ to your actual account table name if different
if (accountGR.get(currentAccount) && accountGR.parent) {
var parentAccount = accountGR.parent.sys_id.toString();
// Get active contacts for the parent account
contactGR.initialize();
contactGR.addQuery('account', parentAccount);
contactGR.addQuery('active', true);
contactGR.query();
while (contactGR.next()) {
approverList.push(contactGR.sys_id.toString());
}
}
// Return the combined list of approver sys_ids
return 'sys_idIN' + approverList.join(',');
})();
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 11:17 AM
Hi Deepak,
Used your script in Script include and called that script include in Reference qualifier. That way it's working as expected. and as you suggested modify the script as per the requirements.
Thanks for providing the script.
Hari Kishan.