Project workspace Slowness issue due to before query business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 05:08 AM
Hi Jaheer,
Hope your doing well.
Need your help.
We are facing the project slowness issue. whenever user open the project workspace it is taking more time to respond back .for that we have raised the case to ServiceNow team they said this is happening due to business rule that is "Before Query Business rule" written on sys_user table which checks the domain of current users also it executes as many times as project tasks in project.
For example: If Project has 10 project tasks then it will execute 10 times to check for the users which are present in that specific domain and My domain has 1000 users that's the reason it is taking time to load.
Can we optimize below is the code in a way that it can improve execution time? Please help me on this.
(function executeRule(current, previous /*null when async*/ ) {
gs.log('Action : ' + gs.action.getGlideURI().toString());
if ((gs.action.getGlideURI().toString().startsWith('api/now/form/mention/record/')) || // for work notes mention
(gs.action.getGlideURI().toString().startsWith('planningconsoleprocessor.do?')) || // for old planning console
(gs.action.getGlideURI().toString().startsWith('api/now/v1/batch?api=api')) || // for new planning console
(gs.action.getGlideURI().toString().startsWith('angular.do?sysparm_type=ref_list_data')) || // for visual task board
(gs.action.getGlideURI().toString().indexOf('sysparm_nameofstack=reflist') > -1) || // for user lookup
(gs.action.getGlideURI().toString().indexOf('sysparm_modify_check=true') > -1))// for form saving
(gs.action.getGlideURI().toString().startsWith('xmlhttp.do?m2m_selected_ids=&sys_target='))) // for m2m window
{
var session = gs.getSession();
var dpSysDomain = session.getCurrentDomainID(); /* set current domain */
var grUser;
var arrUtil = new ArrayUtil();
var arrSysId = [];
var grDomain;
if (dpSysDomain != '') {
grDomain = new GlideRecord('domain');
grDomain.addQuery('sys_id', dpSysDomain);
grDomain.queryNoDomain();
if (grDomain.next()) {
var path = grDomain.getValue('sys_domain_path');
}
var grUserVisibility = new GlideRecord('sys_user_visibility');
grUserVisibility.addQuery('user.active', true);
grUserVisibility.addQuery('sys_domain', grDomain.getUniqueValue());
grUserVisibility.queryNoDomain();
while (grUserVisibility.next()) {
arrSysId.push(grUserVisibility.user.sys_id.toString());
}
grUser = new GlideRecord('sys_user');
grUser.addQuery('active', true);
grUser.addQuery('sys_domain', grDomain.getUniqueValue());
grUser.queryNoDomain();
while (grUser.next()) {
arrSysId.push(grUser.sys_id.toString());
gs.log('Check 4');
}
arrSysId = arrUtil.unique(arrSysId);
current.addEncodedQuery('sys_idIN' + arrSysId.join(','));
gs.info('<DP> sys_idIN + arrSysId.join(,) = ' + 'sys_idIN' + arrSysId.join(','));
}
} else {
grUser = new GlideRecord('sys_user');
grUser.get(gs.getUserID());
current.addQuery('sys_domain' + grUser.sys_domain);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 12:38 AM
@Yasin Shaik11 The domain separation does not require the query business rule to show logged in user specific domain records.
So you can deactivate the BR and set the correct domain in the project records which needs to be visible for user in which domain.
Ex:
Logged in user is part of domain A then he can see the records in all tables where domain is A.
So please check this and i suggest don't use before query business rule.
If you check the domain in query business rule then what's the use of domain separation.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 11:17 PM
Thanks for your reply.
Here i have one question , if I would like to give the cross domain access that is sys_user_visibility . in that case we required this BR. or do we have another option for this ? Please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 11:25 PM
@Yasin Shaik11 There is a concept called visibility domains please check the below link
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023