- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 05:41 AM
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:
(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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 07:19 AM
Keep the if condition and update the below query condition
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 09:57 AM
@Leonel Sandroni wrote:
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!!!
Not quite.
if (udd.next())
: Processes only the first record returned by the query.while (udd.next())
: Processes all records returned by the query.
The code sample I provided is likely the most appropriate way to achieve your requirement. You can also use GlideRecord get: https://www.youtube.com/watch?v=0UNITC4CX7A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 10:34 AM
Ok, with IF...If there were more than one record matched it wouldn't work. I get it! I will try with your suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 07:39 AM - edited 01-27-2025 12:33 PM
Try adding:
udd.setWorkflow(false);
before the
udd.update();
line, to prevent other BRs from running if your goal is to only set that field on the rm_enhancement table.
Or, put in an enhancement request for:
https://www.rfc-editor.org/info/rfc9564
That will speed things up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 07:46 AM
Hi @Leonel Sandroni - What is your requirement?
There is no enhancement field in the rm_enhancement table. When this script runs, a message like 'Invalid query detected, please check logs for details [Unknown field enhancement in table rm_enhancement]' should appear in the system log, indicating the issue.
If you query a table using a field that does not exist (e.g., enhancement in this case), the platform ignores that condition when constructing the query. As a result, the query matches all records in the table. This means the while (udd.next()) loop will iterate over every record in the rm_enhancement table and update the u_due_date field for all records, which is why the script takes so long to execute.
It might run faster in your PDI if there are fewer records in the rm_enhancement table compared to some other instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 08:02 AM
Yes @Sheldon Swift you're right!! it's checkin all the enhancement records because there is no enhancement field.
Anyway, I don't know how to accomplish this requirement. I couldn't find a reference field to a demand table from the enhancement table. I need to modify due_date value in enhancement when the due_date in demands changes (with same value).