BR causing the Performance issue for specific users

Thej1
Tera Expert

Hi,

 

We have a before BR which is causing performance issue for the users of that group. The users are facing larger response time to perform the below operations.

Performance issue for the operations: 

1. To open list of Ritm's in backend

2. To open My Requests in portal

 

Here is the before BR:

Advanced condition - !gs.hasRole('admin') && gs.isInteractive(true)

Script:

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var arr1 = [];
    var grDel = new GlideRecord("sys_user_delegate");
    grDel.addEncodedQuery("ends>javascript:gs.endOfToday()^delegateDYNAMIC90d1921e5f510100a9ad2572f2b477fe^approvals=true");
    grDel.query();
    while (grDel.next()) {
        arr1.push(grDel.getValue("user"));
    }

    var approverQuery = new GlideRecord('sysapproval_approver');
    approverQuery.addEncodedQuery('approver=' + gs.getUserID() + '^ORapproverIN' + arr1.toString());
    //approverQuery.addQuery('approver', gs.getUserID());
    approverQuery.query();
    // Get the sys_ids of RITM records where the current user is an approver
    var ritmSysIds = [];
    while (approverQuery.next()) {
        ritmSysIds.push(approverQuery.getValue('document_id'));
    }

    var taskQuery = new GlideRecord('sc_task');
    taskQuery.addEncodedQuery('request_item.active=true^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744');
    //taskQuery.addQuery('request_item.state','in','1');
    taskQuery.query();
    while (taskQuery.next()) {
        ritmSysIds.push(taskQuery.getValue('request_item'));
    }
   

    var _officeManagementGroup = gs.getProperty('xl_office.management.group');
    if (gs.getUser().isMemberOf(_officeManagementGroup) && gs.hasRole('itil')) {
        current.addEncodedQuery('requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORassignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^ORsys_idIN' + ritmSysIds+'^ORwatch_listDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
     }
    else {
        current.addEncodedQuery('requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORassignment_group!=' + _officeManagementGroup + '^ORassignment_groupISEMPTY^ORsys_idIN' + ritmSysIds+'^ORwatch_listDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
    }

})(current, previous);

 

If condition query is taking larger response time.

I have tried by adding active true and created from last year in query, but no improve in the performance.

 

Can you please suggest any ideas to improve the performance by not changing the logic of code ?

 

Thanks

 

@Community Alums @Kieran Anson @Mark Manders @Amit Gujarathi @Arpan Baishya @Allen Andreas @poojasutar @Pradeep Sharma @Aditya Mallik 

5 REPLIES 5

Mark Manders
Mega Patron

Please, don't just put your script and the result in your question, but also the requirement. Maybe the fact that you are using a script is the issue and another solution can be given to meet the requirement. 

The script itself looks way too heavy, but since you haven't told us what you are trying to achieve, there's not much we can do.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark