Latency in HR To-dos and add Delegate caused by delegation widgetDescriptionWhen user tried to add Delegate or load My Tasks list to-dos in employee center, there is a delay load time of 1-2 minutes. Steps to Reproduce Steps to Reproduce: 1. Open the customer instance 2. Go to the Employee Center Portal 3. Impersonate Employee4. Go to Employee's profile5. Click "Add delegate"6. Add any employee as a delegate 7. After clicking 'Submit', delegate will take a long time to appear on the profile8. Once delegate has appeared, remove the delegate9. Delegate will stay listed until the page is refreshed ------ 1. Open customer instance 2. Go to the Employee Center Portal 3. Impersonate Employee4. Open My tasks5. See initial to-do take about 1-2 minutes to load WorkaroundFiles changed:sys_script_include_fae28675ffb12010a9e7faf9453bf1f9sp_widget_7843ba3fb3361010f5302ddc16a8dca8Issue 1:Slow performance of Delegation page.Investigation:The slowness comes from calls to the API "getAllUserCriteria".Workaround:Files changed: sys_script_include_fae28675ffb12010a9e7faf9453bf1f9sp_widget_7843ba3fb3361010f5302ddc16a8dca8Changes:1. Apply latest version (Tokyo) of Delegation script include to customer instance2. Update Edit Granular Delegation widget variable "USER_CRITERIA" to be:USER_CRITERIA: (function() {var grDelegatorUc = new GlideRecord('sys_m2m_delegator_user_criteria');grDelegatorUc.query();var ucArr = [];while (grDelegatorUc.next())ucArr.push(grDelegatorUc.getValue('user_criteria'));if (!ucArr.length)return [];return sn_uc.UserCriteriaLoader.getMatchingCriteria(gs.getUserID(), ucArr);})(),3. Update Delegation script include API "getGranularDelegates" to use:var ucArr = null;while (granularDelegateGr.next()) {// Only query delegate uc if neededif (ucArr === null) {ucArr = [];var grDelegateUc = new GlideRecord('sys_m2m_delegate_user_criteria');grDelegateUc.query();while (grDelegateUc.next())ucArr.push(grDelegateUc.getValue('user_criteria'));}....if (!gran...)...user_criteria: sn_uc.UserCriteriaLoader.getMatchingCriteria(delegateSysId, ucArr)Issue 2:Slow load performance of My To-dos pageInvestigation:The slowness was not reproducible after the above changes 1-3.- Reverting change 1 showed the slowness again, with a to-do page load time of 1.4m (same time as a call to the getAllUserCriteria API)Conclusion:The changes for Issue 1 appear to resolve issue 2 as well.Related Problem: PRB1599014