Slow performance Business Rule

Leonel Sandroni
Tera Guru

Hi there!

 

I've created a BR in order to update a value from demand tablo to an enhancement table. It's a simple query and no much more...

but for some reason it runs very slow

 

the business rule is an 'after' type with a particular field change and it should modify a field in another table with the same value so:

LeonelSandroni_0-1737639216811.png

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

	// it finds the related enhancement records
        var udd = new GlideRecord('rm_enhancement');
        udd.addQuery('enhancement', current.sys_id); 
        udd.query();

        // set the due date with the same value
        while (udd.next()) {
            udd.u_due_date = current.requested_by; 
            udd.update();
        }


})(current, previous);

 

I tested this BR in PDI and it works fast. 

I used the field 'enhancement' because it is the reference field from demand table to enhancement table and because I couldn't find a reference demand field from the enhancement table.

 

any suggestion?

1 ACCEPTED SOLUTION

Keep the if condition and update the below query condition 

udd.addQuery('sys_id', current.enhancement);
 
let me know if still not working. 


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

View solution in original post

10 REPLIES 10

Rajesh Mushke
Mega Sage
Mega Sage

Hi @Leonel Sandroni,

 

As you are updating the single record right ?

then use the If condition instead of while condition this will fix your issue.

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

	// it finds the related enhancement records
        var udd = new GlideRecord('rm_enhancement');
        udd.addQuery('enhancement', current.sys_id); 
        udd.query();

        // set the due date with the same value
        if (udd.next()) {
            udd.u_due_date = current.requested_by; 
            udd.update();
        }


})(current, previous);


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

I tried with IF instead of WHILE but it doesn't work, the BR does not change the values.

Keep the if condition and update the below query condition 

udd.addQuery('sys_id', current.enhancement);
 
let me know if still not working. 


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Ok, in this way, just check and update the only record that I need!!

 

This is the solution. So...for the next time...When I need to update only one matching record I should use IF inestead WHILE. Thanks!!!