How to optimize this code which is being called via onChange Client Script
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 11:28 PM
Hi Team,
I have written the below part of script include which I am calling via OnChange Client Script and GlideAjax.Here type is 10 means we want to add all the accounts w
if (type == 10) {
var add = new GlideRecord('customer_account');
add.addEncodedQuery('account_pathSTARTSWITH' + con_rel.account.account_path + '^account_parentISNOTEMPTY^u_active=true');
add.query();
while (add.next()) {
var addresp = new GlideRecord('sn_customerservice_contact_relationship');
addresp.addQuery('contact', con_rel.sys_id.toString());
addresp.addQuery('company', add.sys_id.toString());
addresp.addQuery('u_authority_role', res);
addresp.query();
// Here if the Data is not found we are adding the accounts to the array.The accounts can be more than 1200 records. The system gets stuck after I click on Accounts reference field after selectin Type as 10 on the form.Here the requirement is if the these accounts are not added to the contact those should showup
if (!addresp.next()) {
accounts = add.sys_id.toString();
arr.push(accounts);
}
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 02:15 AM
Hi Ankur,
Building a query triggered by client action over 1200 records is always a challenge. Things you can do to make a query go smoother is checken the table for Indexing and/or trying to look at pagination query. Check this article for example: GlideRecord Pagination - Page through your GlideRecord query - ServiceNow Developer Pro-Tips
Hope this gives you some guidons.
Kind Regards,
Collin